我试图通过传递一个配置文件来实现stop或rm服务,但这会停止所有服务,而不是只停止使用该配置文件的服务。up命令似乎运行良好--这是我的docker-compose.yaml版本:'3.9‘
services:
registry:
container_name: registry
image: registry:latest
pull_policy: missing
profiles:
- registry_service_profile
...
portainer:
container_name: portainer
image: localhost:5000/my-portainer
pull_policy: missing
profiles:
- other_services_profile
...
pihole:
container_name: pihole
image: localhost:5000/my-pihole
pull_policy: missing
profiles:
- other_services_profile
...
bitwarden:
container_name: bitwarden
image: localhost:5000/my-bitwarden
profiles:
- other_services_profile
pull_policy: missing
...
homeassistant:
container_name: homeassistant
image: localhost:5000/my-homeassistant
pull_policy: missing
profiles:
- other_services_profile
...
duplicati:
container_name: duplicati
image: localhost:5000/my-duplicati
pull_policy: missing
profiles:
- other_services_profile
...使用这两个配置文件运行停止命令将停止所有服务,而不仅仅是具有所提供的配置文件的服务。
user@pc:/opt/docker$ sudo docker compose --profile registry_service_profile stop
[+] Running 6/6
⠿ Container pihole Stopped 4.6s
⠿ Container portainer Stopped 0.7s
⠿ Container registry Stopped 0.4s
⠿ Container homeassistant Stopped 5.0s
⠿ Container bitwarden Stopped 0.5s
⠿ Container duplicati Stopped 4.5s
user@pc:/opt/docker$ sudo docker compose --profile registry_service_profile up --detach
[+] Running 1/1
⠿ Container registry Started 0.4s
user@pc:/opt/docker$ sudo docker compose --profile other_services_profile up --detach
[+] Running 5/5
⠿ Container portainer Started 0.7s
⠿ Container homeassistant Started 0.2s
⠿ Container bitwarden Started 0.6s
⠿ Container pihole Started 0.9s
⠿ Container duplicati Started 0.9s
user@pc:/opt/docker$ sudo docker compose --profile other_services_profile stop
[+] Running 6/6
⠿ Container portainer Stopped 0.4s
⠿ Container pihole Stopped 4.5s
⠿ Container registry Stopped 0.6s
⠿ Container duplicati Stopped 4.4s
⠿ Container homeassistant Stopped 5.0s
⠿ Container bitwarden Stopped 0.5s
user@pc:/opt/docker$ docker --version
Docker version 20.10.17, build 100c701我做错了什么吗?
或者我应该只运行docker compose up命令,它应该将服务更新为最新的拉出版本?
发布于 2022-09-06 13:04:00
看起来,您只想停止包含配置文件other_services_profile的服务,而不是所有容器。
我认为你做不到,这仍然是一个码头写作的问题。
https://github.com/docker/compose/issues/8139
注意:我试图复制它,对我来说,这种行为发生在使用docker compose --profile other_services_profile stop时,而不是在使用docker compose --profile other_services_profile down时,在这种情况下,它只删除了该配置文件的所有容器(您也会得到一条消息,它试图删除默认网络,但只要有一个容器仍在运行)。
(我在窗户上使用码头20.10.17 )
发布于 2022-09-06 12:29:51
这是一个实现选择。配置文件仅在创建或启动服务时工作。看看这条线
https://stackoverflow.com/questions/73621744
复制相似问题