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

Cannot use shell form for command specified in Compose file #12403

Open
ijessen-mitll opened this issue Dec 18, 2024 · 3 comments
Open

Cannot use shell form for command specified in Compose file #12403

ijessen-mitll opened this issue Dec 18, 2024 · 3 comments

Comments

@ijessen-mitll
Copy link

Description

A command override in a Compose service definition will never execute in shell form, only ever exec form. This is contrary to the documentation statement that "the value can also be a list, in a manner similar to Dockerfile". A Dockerfile CMD specified as a list triggers exec form, while a Dockerfile CMD specified as a plain string triggers shell form (see here).

Steps To Reproduce

Example compose.yaml:

services:

  exec-form:
    image: alpine:latest
    command: ["/bin/sh", "-c", "echo $$HOSTNAME"]

  shell-form-compose:
    image: alpine:latest
    command: echo $$HOSTNAME

  shell-form-dockerfile:
    build:
      dockerfile_inline: |
        FROM alpine:latest
        CMD echo $$HOSTNAME
    image: alpine:latest

Results (notice the difference between the compose shell form output from the other two):

$ docker compose -f compose.yaml up
[+] Running 3/0
 ✔ Container config-exec-form-1              Created         0.0s 
 ✔ Container config-shell-form-compose-1     Created         0.0s 
 ✔ Container config-shell-form-dockerfile-1  Created         0.0s 


exec-form-1               | 03eae6e24cbf
shell-form-compose-1      | $HOSTNAME
shell-form-dockerfile-1   | 2d7438fcb6a1

Compose Version

Docker Compose version v2.31.0

Docker Environment

Client: Docker Engine - Community
 Version:    27.4.0
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.19.2
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.31.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Anything else?

If the behavior is as-intended, the Compose reference documentation should be updated to clarify that a string command will be executed in exec mode (contrary to the Dockerfile behavior).

@ndeloof
Copy link
Contributor

ndeloof commented Dec 19, 2024

This is the expected behavior
"in a manner similar to Dockerfile" indeed is weaving hands without a clear definition in docs, need to be clarified.

@ijessen-mitll
Copy link
Author

For completeness - why is this intended behavior?

@ndeloof
Copy link
Contributor

ndeloof commented Dec 19, 2024

Basically: preserve backward compatibility

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

No branches or pull requests

2 participants