[英]How to implement changes made to docker-compose.yml to detached running containers
The project is currently running in the background from this command:该项目当前正在通过此命令在后台运行:
docker-compose up -d
I need to make two changes to their docker-compose.yml
:我需要对他们
docker-compose.yml
做两个更改:
- Add a new container
添加一个新容器
- Update a previous container to have a link to the new container
更新以前的容器以链接到新容器
After changes are made:更改后:
NOTE the " <--
" arrows for my changes注意我的更改的“
<--
”箭头
web:
build: .
restart: always
command: ['tini', '--', 'rails', 's']
environment:
RAILS_ENV: production
HOST: example.com
EMAIL: admin@example.com
links:
- db:mongo
- exim4:exim4.docker # <-- Add link
ports:
- 3000:3000
volumes:
- .:/usr/src/app
db:
image: mongo
restart: always
exim4: # <-------------------------------- Add new container
image: exim4
restart: always
ports:
- 25:25
environment:
EMAIL_USER: user@example.com
EMAIL_PASSWORD: abcdabcdabcdabcd
After making the changes, how do I apply them?进行更改后,如何应用它们? (without destroying anything)
(不破坏任何东西)
I tried docker-compose down && docker-compose up -d
but this destroyed the Mongo DB container... I cannot do that... again... :sob:我试过
docker-compose down && docker-compose up -d
但这破坏了 Mongo DB 容器......我不能这样做......再次...... :sob:
docker-compose restart
says it won't recognize any changes made to docker-compose.yml
(Source: https://docs.docker.com/compose/reference/restart/) docker-compose restart
表示它不会识别对docker-compose.yml
所做的任何更改(来源: https : docker-compose.yml
)
docker-compose stop && docker-compose start
sounds like it'll just startup the old containers without my changes? docker-compose stop && docker-compose start
听起来它只会在没有我更改的情况下启动旧容器?
Test server:测试服务器:
Production server is likely using older versions, unsure if that will be an issue?生产服务器可能使用旧版本,不确定这是否会成为问题?
If you just run docker-compose up -d
again, it will notice the new container and the changed configuration and apply them.如果您再次运行
docker-compose up -d
,它会注意到新容器和更改的配置并应用它们。
But:但:
(without destroying anything)
(不破坏任何东西)
There are a number of settings that can only be set at container startup time.有许多设置只能在容器启动时设置。 If you change these, Docker Compose will delete and recreate the affected container.
如果您更改这些,Docker Compose 将删除并重新创建受影响的容器。 For example, links are a startup-only option, so re-running
docker-compose up -d
will delete and recreate the web
container.例如,链接是仅启动选项,因此重新运行
docker-compose up -d
将删除并重新创建web
容器。
this destroyed the Mongo DB container... I cannot do that... again...
这破坏了 Mongo DB 容器......我不能那样做......再次......
db:
image: mongo
restart: always
Add a volumes:
option to this so that data is stored outside the container.添加一个
volumes:
选项,以便数据存储在容器外。 You can keep it in a named volume, possibly managed by Docker Compose, which has some advantages, but a host-system directory is probably harder to accidentally destroy.您可以将它保存在一个命名卷中,可能由 Docker Compose 管理,这有一些优点,但主机系统目录可能更难意外销毁。 You will have to delete and restart the container to change this option.
您必须删除并重新启动容器才能更改此选项。 But note that you will also have to delete and restart the container if, for example, there is a security update in MongoDB and you need a new image.
但请注意,例如,如果 MongoDB 中存在安全更新并且您需要一个新映像,则您还必须删除并重新启动容器。
Your ideal state here is:您在这里的理想状态是:
If you lose your entire /var/lib/docker
directory (which happens!) you shouldn't actually lose any state, though you will probably wind up with some application downtime.如果您丢失了整个
/var/lib/docker
目录(发生了!),您实际上不应该丢失任何状态,尽管您可能会导致一些应用程序停机。
Just docker-compose up -d
will do the job.只需
docker-compose up -d
就可以完成这项工作。
Output should be like输出应该像
> docker-compose up -d
Starting container1 ... done
> docker-compose up -d
container1 is up-to-date
Creating container2 ... done
As a side note, docker-compose is not really for production.附带说明一下,docker-compose 并不是真正用于生产。 You may want to consider docker swarm.
您可能需要考虑 docker swarm。
the key here is that up
is idempotent.这里的关键是
up
是幂等的。
if you update configuration in docker-compose.yaml如果您更新 docker-compose.yaml 中的配置
docker compose up -d
If compose is building images before run it, and you want to rebuild them:如果 compose 在运行之前正在构建图像,并且您想重建它们:
docker compose up -d --build
The project is currently running in the background from this command:该项目当前正在此命令在后台运行:
docker-compose up -d
I need to make two changes to their docker-compose.yml
:我需要对其
docker-compose.yml
进行两项更改:
- Add a new container
添加一个新的容器
- Update a previous container to have a link to the new container
更新以前的容器以具有指向新容器的链接
After changes are made:进行更改后:
NOTE the " <--
" arrows for my changes注意我的更改的“
<--
”箭头
web:
build: .
restart: always
command: ['tini', '--', 'rails', 's']
environment:
RAILS_ENV: production
HOST: example.com
EMAIL: admin@example.com
links:
- db:mongo
- exim4:exim4.docker # <-- Add link
ports:
- 3000:3000
volumes:
- .:/usr/src/app
db:
image: mongo
restart: always
exim4: # <-------------------------------- Add new container
image: exim4
restart: always
ports:
- 25:25
environment:
EMAIL_USER: user@example.com
EMAIL_PASSWORD: abcdabcdabcdabcd
After making the changes, how do I apply them?进行更改后,如何应用它们? (without destroying anything)
(不破坏任何东西)
I tried docker-compose down && docker-compose up -d
but this destroyed the Mongo DB container... I cannot do that... again... :sob:我尝试了
docker-compose down && docker-compose up -d
但这破坏了Mongo DB容器...我再也不能这样做...:sob:
docker-compose restart
says it won't recognize any changes made to docker-compose.yml
(Source: https://docs.docker.com/compose/reference/restart/) docker-compose restart
表示无法识别对docker-compose.yml
所做的任何更改(来源: https : docker-compose.yml
)
docker-compose stop && docker-compose start
sounds like it'll just startup the old containers without my changes? docker-compose stop && docker-compose start
听起来像只是在不做任何更改的情况下启动旧容器?
Test server:测试服务器:
Production server is likely using older versions, unsure if that will be an issue?生产服务器可能使用较旧的版本,不确定是否会出现问题?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.