It appears that the command override in a Compose service definition will never execute in shell form, only ever exec form. This is contrary to the Compose reference documentation’s statement that “the value can also be a list, in a manner similar to Dockerfile”, as a list in a Dockerfile CMD triggers exec form, while a plain string triggers shell form.
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