首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么停止或rm与配置文件停止所有服务?

为什么停止或rm与配置文件停止所有服务?
EN

Stack Overflow用户
提问于 2022-09-06 12:03:41
回答 2查看 49关注 0票数 0

我试图通过传递一个配置文件来实现stoprm服务,但这会停止所有服务,而不是只停止使用该配置文件的服务。up命令似乎运行良好--这是我的docker-compose.yaml版本:'3.9‘

代码语言:javascript
复制
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
    ...

使用这两个配置文件运行停止命令将停止所有服务,而不仅仅是具有所提供的配置文件的服务。

代码语言:javascript
复制
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命令,它应该将服务更新为最新的拉出版本?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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 )

票数 1
EN

Stack Overflow用户

发布于 2022-09-06 12:29:51

这是一个实现选择。配置文件仅在创建或启动服务时工作。看看这条线

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73621744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档