我有以下 docker-compose 配置:
version: '2'
services:
nginx:
image: 'nginx:latest'
expose:
- '80'
- '8080'
container_name: nginx
ports:
- '80:80'
- '8080:8080'
volumes:
- '/home/ubuntu/nginx.conf:/etc/nginx/nginx.conf'
networks:
- default
restart: always
inmates:
image: 'xxx/inmates:mysql'
container_name: 'inmates'
expose:
- '3000'
env_file: './inmates.env'
volumes:
- inmates_documents_images:/data
- inmates_logs:/logs.log
networks:
- default
restart: always
we19:
image: 'xxx/we19:dev'
container_name: 'we19'
expose:
- '3000'
env_file: './we19.env'
volumes:
- we19_logs:/logs.log
networks:
- default
restart: always
desktop:
image: 'xxx/desktop:dev'
container_name: 'desktop'
expose:
- '3000'
env_file: './desktop.env'
volumes:
- desktop_logs:/logs.log
networks:
- default
restart: always
volumes:
inmates_documents_images:
inmates_logs:
desktop_logs:
we19_logs:
假设我做了docker-compose up -d --buiild
。
现在 4 个容器(服务)正在运行。
现在,我想用新内容更新 ./desktop.env
文件。有没有可能用新的 env 文件重置 desktop
容器?还是需要 docker-compose restart
?
基本上,我试图仅使用新的 env 文件重新启动 desktop
容器,但在不重新启动它们的情况下保持所有其他 3 个容器运行。
答案 0 :(得分:0)
从 docker-compose up --help
中提取
[...]
如果服务存在现有容器,并且在创建容器后更改了服务的配置或映像,docker-compose up
会通过停止和重新创建容器(保留安装的卷)来获取更改。要防止 Compose 获取更改,请使用 --no-recreate
标志。
[...]
用法:up [options] [--scale SERVICE=NUM...] [SERVICE...]
[...]
以下命令应该可以解决您的问题。
docker-compose up -d desktop
如果没有,请参阅文档以了解可用于满足您确切要求的其他选项(例如 --force-recreate
、--renew-anon-volumes
、...)