[BUG] docker compose up fails to capture stdout when dockerfile directory is not the same as the build context
Description
My goal was to write a minimal Dockerfile and docker-compose.yml, which would print "Hello World" to stdout when I run docker compose up. When the Dockerfile and docker-compose.yml are in the same directory it works, but when the Dockerfile is instead inside a subdirectory, it doesn't work: I don't see any output from the echo command set as the CMD in the Dockerfile.
I've attached some screenshots, since in this case, all the code is short enough to fit in a single screenshot.
Here is a screenshot of the first scenario, where everything is in one directory, and I see the output I expect:
Here is the situation where the Dockerfile is in a subdirectory:
Here is a work-around where I override the CMD in the Dockerfile in the docker-compose.yml:
In all three scenarios, I expect to see the output from the echo command. I don't understand what is happening in that second screenshot.
Steps To Reproduce
- On a Windows machine, create a Dockerfile and docker-compose.yml as shown in screenshot. Text is provided in the "Anything Else" section.
- Run docker compose up in the project root, look for the output of the echo command as specified in the Dockerfile
Compose Version
Docker Compose version v2.22.0-desktop.2
Docker Compose version v2.22.0-desktop.2
Docker Environment
Client:
Version: 24.0.6
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.11.2-desktop.5
Path: C:\Program Files\Docker\cli-plugins\docker-buildx.exe
compose: Docker Compose (Docker Inc.)
Version: v2.22.0-desktop.2
Path: C:\Program Files\Docker\cli-plugins\docker-compose.exe
dev: Docker Dev Environments (Docker Inc.)
Version: v0.1.0
Path: C:\Program Files\Docker\cli-plugins\docker-dev.exe
extension: Manages Docker extensions (Docker Inc.)
Version: v0.2.20
Path: C:\Program Files\Docker\cli-plugins\docker-extension.exe
init: Creates Docker-related starter files for your project (Docker Inc.)
Version: v0.1.0-beta.8
Path: C:\Program Files\Docker\cli-plugins\docker-init.exe
sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
Version: 0.6.0
Path: C:\Program Files\Docker\cli-plugins\docker-sbom.exe
scan: Docker Scan (Docker Inc.)
Version: v0.26.0
Path: C:\Program Files\Docker\cli-plugins\docker-scan.exe
scout: Docker Scout (Docker Inc.)
Version: v1.0.7
Path: C:\Program Files\Docker\cli-plugins\docker-scout.exe
Server:
Containers: 1
Running: 1
Paused: 0
Stopped: 0
Images: 300
Server Version: 24.0.6
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: cgroupfs
Cgroup Version: 1
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.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 8165feabfdfe38c65b599c4993d227328c231fca
runc version: v1.1.8-0-g82f18fe
init version: de40ad0
Security Options:
seccomp
Profile: unconfined
Kernel Version: 5.15.133.1-microsoft-standard-WSL2
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 12
Total Memory: 15.53GiB
Name: docker-desktop
ID: c14ab755-04e3-4b5a-97a1-b34c9904cb65
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
Experimental: false
Insecure Registries:
hubproxy.docker.internal:5555
127.0.0.0/8
Live Restore Enabled: false
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile
Anything else?
Scenario that is not working:
Docker compose for when Dockerfile is in subdirectory:
version: '3'
services:
myapp:
build:
context: .
dockerfile: docker/Dockerfile
command: echo "This command overrides CMD in Dockerfile."
# tty: true
Dockerfile in subdirectory:
FROM python
CMD ["echo", "Hello World"]
Scenario that works as I expect:
Docker compose file in same directory:
version: '3'
services:
app:
build: .
Dockerfile in same directory:
FROM python
CMD ["echo", "Hello flat World"]
Tried to reproduce without success (and can't see any reason Dockerfile path would have any impact on execution of the built image)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Tested this again after getting the stale notification: can't reproduce it, closing issue