I’m trying to stop
or rm
services by passing a profile, but this stops all services instead of just the one with this profile.
The up
command seems to work fine
This is my docker-compose.yaml
version: ‘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
...
Running the stop command with both profiles stops all services, not just the ones with the provided 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
Am I doing something wrong?
Or I should just run docker compose up
command and this should update the services to the latest pulled version?
2
Answers
This is an implementation choice. The profiles only work when creating or starting services. Take a look at this thread
Looks like you want to stop only the services that contains the profile
other_services_profile
and not all the containersI think you can’t and this is still an issue of docker compose
https://github.com/docker/compose/issues/8139
NB: I tried to reproduce it, for me this behavior happens when using
docker compose --profile other_services_profile stop
but not when using
docker compose --profile other_services_profile down
, in this case it remove all containers with only that profile (you will also get a message of it trying to delete the default network aswell but cannot as long as there is one container running still using it)(I use docker 20.10.17 on windows)