Skip to content

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

Open
compose-spec/compose-spec
#557
@ijessen-mitll

Description

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).

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions