Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] docker compose start/stop/restart does not automatically enable profiles with explicitly targeted service #9986

Closed
Valgard opened this issue Nov 9, 2022 · 4 comments · Fixed by #10025

Comments

@Valgard
Copy link

Valgard commented Nov 9, 2022

Description

I have a docker compose file like this:

services:

  app1:
    [...]

  app2:
    [...]
    profiles:
    - app2

I can bring up app2 with docker compose up app2.

But the commands

  • docker compose start app2
  • docker compose stop app2
  • docker compose restart app2

do not automatically enable profile app2 and fail silently or with message no such service: app2.

Regading Using service profiles and Compose Specification i expected that the commands automatically enable the profile.

Steps To Reproduce

  1. With this config
services:
  app1:
    image: hello-world
  
  app2:
    image: hello-world
    profiles:
      - app2
  1. Run docker compose up -d app2
  2. docker compose start app2 fails with message no such service: app2
  3. docker compose stop app2 fails silently
  4. docker compose start app2 fails silently

Compose Version

$ docker compose version                                                                                                                                                      
Docker Compose version v2.12.1

$ docker-compose version                                                                                                                                                      
Docker Compose version v2.12.1

Docker Environment

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.9.1)
  compose: Docker Compose (Docker Inc., v2.12.1)
  dev: Docker Dev Environments (Docker Inc., v0.0.3)
  extension: Manages Docker extensions (Docker Inc., v0.2.13)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.21.0)

Server:
 Containers: 18
  Running: 12
  Paused: 0
  Stopped: 6
 Images: 13
 Server Version: 20.10.20
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.49-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 6
 Total Memory: 19.55GiB
 Name: docker-desktop
 ID: WQ3P:EAX7:2L4Y:A4R3:YW4L:IHXR:BI2V:S723:CUXF:HMFL:WKIN:BUHB
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

@glours
Copy link
Contributor

glours commented Nov 9, 2022

Hello @Valgard
If you look closely to the profile documentation you will see

If unassigned, the service is always started but if assigned, it is only started if the profile is activated.

That means you should explicitly give the information to Compose using the --profile flag.
In your case the commands should start with docker compose --profile app2 ...
If you want to run your stack with both app1 and app2 services you should do docker compose --profile app2 up
For the start it will be docker compose --profile app2 start app2, etc...

@Valgard
Copy link
Author

Valgard commented Nov 10, 2022

Hello @glours
I have seen this part of the profile documentation. But further down under the point Auto-enabling profiles and dependency resolution is the following

When a service with assigned profiles is explicitly targeted on the command line its profiles will be enabled automatically so you don’t need to enable them manually.

The Compose specification also specifies under the point Illustrative example following

If Compose implementation is executed with bar as explicit service to run, it and the test profile will be active even if test profile is not enabled by the user.

So this means for me when I run docker compose start app2 the profile app2 should activate automatically and start the service app2. But i get the message no such service: app2.

The same behaviour should also apply to stop and restart.

So for me its is a bug in docker compose or the documentation is misleading.

@Valgard
Copy link
Author

Valgard commented Nov 24, 2022

Hello @glours , Hello @nicksieger , Hello @nicks ,

it would be really nice of you if I could get an answer to my last comment.

Regards,
@Valgard

@glours
Copy link
Contributor

glours commented Nov 24, 2022

@Valgard I'll take look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants