Skip to content

direct command to compose down services a specific profile without down default services #13993

Description

@h3110Fr13nd

problem description

there’s no proper way to compose down only a profile’s services without specifying specific service names or getting default services down along as well.

i understand the current ideology of having default(core) services getting up along with any profile(s). Though now I want to keep my core services running but compose down my other profiles. the only way is to:

docker compose down <profile_service_name_1> <profile_service_name_2>

as if you do

docker compose --profile=xyz down

removes the default services along, which is expected as per docs: https://docs.docker.com/compose/how-tos/profiles/?uuid=46ec72e8-3598-42b7-876d-6ce34666bad9#stop-application-and-services-with-specific-profiles

however that’s inconvenient. we might nest command to get services names dynamically from config maybe. but hard to get around such complex command.

is there some ideal way. Or can we introduce something for this?

proposed approaches & community discussion

after discussing on community forum:
https://forums.docker.com/t/direct-command-to-compose-up-down-a-profile-without-up-down-default/152172

Metin Y suggested an argument addition --profile-only in the compose down action.

i assume that's a little difficult as --profile argument is for compose and not of up/down/logs/stop.
adding a new arg might be a heavy task.

another approach I can think of is firstly
allow multiple comma separated profile:

docker compose --profile="hi,bye" up

then we can introduce something like a tilde at the beginning to indicate only this profile(s):

docker compose --profile="~hi,bye" down

this may seem to be a bit confusing as well, there's a requirement for a convenient way.

additional proposal: Container labels for profiles

additionally there should be proper and easier way to filter out the containers based on profile, this might help to at least get more convenient way to inspect and get information without having to have the knowledge of source path of config files.

docker inspect <id> already contains com.docker.compose.project, com.docker.compose.project.config_files, com.docker.compose.project.working_dir in [0].Config.Labels which I'm assuming are there for the similar reasons I'm proposing. having com.docker.compose.profile in the labels would be a great addition to filter out containers based on profile name like docker (compose) ps --filter "label=com.docker.compose.profile=xyz".

might be worth delegating to a sub issue/task and/or good first issue. lmk.

current workarounds vs ideal commands

current way of getting down the services of a project for specified profiles without removing default is:

export PROJECT="myproject" PROFILE="abc,xyz"

export CFG=$(docker compose ls --format json | jq -r --arg p "$PROJECT" '.[]|select(.Name==$p)|.ConfigFiles' | tr ',' ':')

COMPOSE_FILE=$CFG COMPOSE_PROFILES=$PROFILE docker compose -p "$PROJECT" config --format json | jq -r --arg p "$PROFILE" '($p|split(",")) as $r | .services|to_entries[]|select(.value.profiles and any(.value.profiles[]; IN($r[])))|.key' | xargs -r docker compose -p "$PROJECT" down

if docker ps --filter "label=com.docker.compose.profile=abc,xyz" worked that could become:

PROJECT="myproject" PROFILE="HIII,THAI"; docker compose -p "$PROJECT" down $(docker ps -a --filter "label=com.docker.compose.project=$PROJECT" $(printf ' --filter label=com.docker.compose.profile=%s' ${PROFILE//,/ }) --format '{{.Label "com.docker.compose.service"}}' | sort -u)

and if docker compose ps --filter "label=com.docker.compose.profile=abc,xyz" worked that could become:

PROJECT="myproject" PROFILE="HIII,THAI"; docker compose -p "$PROJECT" down $(docker compose -p "$PROJECT" ps -a $(printf ' --filter label=com.docker.compose.profile=%s' ${PROFILE//,/ }) --format '{{.Label "com.docker.compose.service"}}' | sort -u)

even after shortening the command is not short enough

ideal or expecting something like:

docker compose -p <project> --profile-only=profile1,profile2 down
# or
docker compose -p <project> --profile=~profile1,profile2 down

clean and intuitive.

ps note: the above commands are big cuz I run many projects on my pc(10+ projects, 6-7 services each) hard not to lose track, most with restarts and clashing ports. while default services are what i want to keep for my teammates, i want to down the other profile ones without actually going to that folder/location. vscode-containers extensions is no help cuz it contains no profile info. though i've customized the extension for me, but doesn't help much my team. and using ai agent is no help, cuz agents don't even know we can compose down specific services.


info on what i have:

h3110fr13nd@rog:~$ docker version
Client: Docker Engine - Community
 Version:           29.7.1
 API version:       1.55
 Go version:        go1.26.5
 Git commit:        e9452d6
 Built:             Fri Jul 31 17:06:16 2026
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          29.7.1
  API version:      1.55 (minimum version 1.40)
  Go version:       go1.26.5
  Git commit:       c5b8ce9
  Built:            Fri Jul 31 17:06:16 2026
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v2.2.6
  GitCommit:        11ce9d5f3c68c941867e82890e93e815c1304f1b
 runc:
  Version:          1.3.6
  GitCommit:        v1.3.6-0-g491b69ba
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
h3110fr13nd@rog:~$ docker context show
default
docker info
Client: Docker Engine - Community
 Version:    29.7.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.36.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v5.3.1
    Path:     /usr/libexec/docker/cli-plugins/docker-compose
  model: Docker Model Runner (Docker Inc.)
    Version:  v1.2.6
    Path:     /usr/libexec/docker/cli-plugins/docker-model
  scout: Docker Scout (Docker Inc.)
    Version:  v1.10.0
    Path:     /home/h3110fr13nd/.docker/cli-plugins/docker-scout

Server:
 Containers: 8
  Running: 0
  Paused: 0
  Stopped: 8
 Images: 30
 Server Version: 29.7.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 nvidia runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 11ce9d5f3c68c941867e82890e93e815c1304f1b
 runc version: v1.3.6-0-g491b69ba
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 7.0.0-28-generic
 Operating System: Ubuntu 26.04 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 14.38GiB
 Name: rog
 ID: 1fea1183-a226-49b9-8eb0-8e060ffa3fe7
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false
 Firewall Backend: iptables
  EnableUserlandProxy: true
  UserlandProxyPath: /usr/bin/docker-proxy

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions