When using Rails inside a Docker container several posts, (including one on docker.com) use the following pattern:
在Docker容器中使用Rails时,几个帖子(包括docker.com上的一个)使用以下模式:
- In
Dockerfile
doADD Gemfile
andADD Gemfile.lock
, thenRUN bundle install
. - 在Dockerfile中执行ADD Gemfile和ADD Gemfile.lock,然后运行RUN bundle install。
- Create a new Rails app with
docker-compose run web rails new
. - 使用docker-compose运行web rails new创建一个新的Rails应用程序。
Since we RUN bundle install
to build the image, it seems appropriate to docker-compose build web
after updating the Gemfile
.
由于我们运行捆绑安装来构建映像,因此在更新Gemfile之后,对于构建Web构建web似乎是合适的。
This works insomuch as the gemset will be updated inside the image, but:
这样可以在图像内部更新gemset,但是:
The Gemfile.lock
on the Docker host will not be updated to reflect the changes to the Gemfile
. This is a problem because:
Docker主机上的Gemfile.lock不会更新以反映Gemfile的更改。这是一个问题,因为:
-
Gemfile.lock
should be in your repository, and:Gemfile.lock应该在您的存储库中,并且:
-
It should be consistent with your current
Gemfile
.它应该与您当前的Gemfile一致。
So:
所以:
How can one update the Gemfile.lock
on the host, so it may be checked in to version control?
如何更新主机上的Gemfile.lock,以便可以检入版本控制?
3 个解决方案
#1
6
Executing the bundle
inside run
does update the Gemfile.lock
on the host:
在运行中执行bundle会更新主机上的Gemfile.lock:
docker-compose run web bundle
However: You must still also build
the image again.
但是:您还必须再次构建映像。
#2
2
TL;DR - make the changes on the container, run bundle on the container and restart for good measure. Locally these changes will be reflected in your app and are ready to test/push out to git, and your production server will use it to rebuild.
TL; DR - 对容器进行更改,在容器上运行bundle并重新启动以获得良好的度量。本地这些更改将反映在您的应用程序中,并准备测试/推送到git,您的生产服务器将使用它进行重建。
Long; Read:
-
docker exec -it name_of_app_1 bash
docker exec -it name_of_app_1 bash
-
vim Gemfile
and put something likegem 'sorcery', '0.9.0'
I feel this ensures you get the version you're looking forvim Gemfile并添加类似gem'jecery','0.9.0'的东西我觉得这可以确保你得到你正在寻找的版本
-
bundle
to get just this version in the current container'sGemfile
andGemfile.lock
bundle来获取当前容器的Gemfile和Gemfile.lock中的这个版本
This has been semi normal "Rails" type stuff here, just you are doing it on the container that is running. Now you don't have to worry about git and getting these changes onto. your git repo because these changes are all happening on your local copy. So like, open a terminal tab and go into your app and less Gemfile
and you should see the changes.
这是半正常的“Rails”类型的东西,只是你在正在运行的容器上这样做。现在你不必担心git并将这些更改发现。你的git repo,因为这些更改都发生在你的本地副本上。所以,打开一个终端选项卡,然后进入你的应用程序,减少Gemfile,你应该看到更改。
- Now you can restart your running container. Your Dockerfile will get rebuilt (in my case by
docker-compose up
locally, tests should pass. Browser test at will. - 现在您可以重新启动正在运行的容器您的Dockerfile将被重建(在我的情况下由docker-compose up在本地,测试应该通过。浏览器测试随意。
Commit your changes to git and use your deploy process to check it out on staging.
将您的更改提交给git并使用您的部署过程在暂存时检查它。
Notes:
Check that Dockerfile
like the OP's links say. I'm assuming that you have some kind of bundle
or bundle install
line in your Dockerfile
检查Dockerfile是否与OP的链接一样。我假设您的Dockerfile中有某种捆绑或捆绑安装行
#3
2
Just to be clear, the commands to run are:
为了清楚起见,运行的命令是:
docker-compose run web bundle
docker-compose up --build
where web is the name of your Dockerized Rails app.
其中web是Dockerized Rails应用程序的名称。
#1
6
Executing the bundle
inside run
does update the Gemfile.lock
on the host:
在运行中执行bundle会更新主机上的Gemfile.lock:
docker-compose run web bundle
However: You must still also build
the image again.
但是:您还必须再次构建映像。
#2
2
TL;DR - make the changes on the container, run bundle on the container and restart for good measure. Locally these changes will be reflected in your app and are ready to test/push out to git, and your production server will use it to rebuild.
TL; DR - 对容器进行更改,在容器上运行bundle并重新启动以获得良好的度量。本地这些更改将反映在您的应用程序中,并准备测试/推送到git,您的生产服务器将使用它进行重建。
Long; Read:
-
docker exec -it name_of_app_1 bash
docker exec -it name_of_app_1 bash
-
vim Gemfile
and put something likegem 'sorcery', '0.9.0'
I feel this ensures you get the version you're looking forvim Gemfile并添加类似gem'jecery','0.9.0'的东西我觉得这可以确保你得到你正在寻找的版本
-
bundle
to get just this version in the current container'sGemfile
andGemfile.lock
bundle来获取当前容器的Gemfile和Gemfile.lock中的这个版本
This has been semi normal "Rails" type stuff here, just you are doing it on the container that is running. Now you don't have to worry about git and getting these changes onto. your git repo because these changes are all happening on your local copy. So like, open a terminal tab and go into your app and less Gemfile
and you should see the changes.
这是半正常的“Rails”类型的东西,只是你在正在运行的容器上这样做。现在你不必担心git并将这些更改发现。你的git repo,因为这些更改都发生在你的本地副本上。所以,打开一个终端选项卡,然后进入你的应用程序,减少Gemfile,你应该看到更改。
- Now you can restart your running container. Your Dockerfile will get rebuilt (in my case by
docker-compose up
locally, tests should pass. Browser test at will. - 现在您可以重新启动正在运行的容器您的Dockerfile将被重建(在我的情况下由docker-compose up在本地,测试应该通过。浏览器测试随意。
Commit your changes to git and use your deploy process to check it out on staging.
将您的更改提交给git并使用您的部署过程在暂存时检查它。
Notes:
Check that Dockerfile
like the OP's links say. I'm assuming that you have some kind of bundle
or bundle install
line in your Dockerfile
检查Dockerfile是否与OP的链接一样。我假设您的Dockerfile中有某种捆绑或捆绑安装行
#3
2
Just to be clear, the commands to run are:
为了清楚起见,运行的命令是:
docker-compose run web bundle
docker-compose up --build
where web is the name of your Dockerized Rails app.
其中web是Dockerized Rails应用程序的名称。