-
Notifications
You must be signed in to change notification settings - Fork 136
Description
Description
It seems that closing stdin using the bash exec builtin (i.e. running bash -c 'exec 0<&- ...') when running a command in a Docker container behaves differently when running an emulated amd64 container, rather than a native arm64 container. Specifically, on amd64 containers stdin/fd 0 ends up being reopened and pointing to a binary file instead, said binary file appearing to us to reliably be the program passed to exec. This has caused all kinds of weird issues when testing programs locally on Macs.
I've tried running the same commands below (minus --platform) on an amd64 Linux machine with Docker CE, as well as directly running equivalent commands in the shell on the same Linux and macOS machines, and don't experience the same issues there.
Reproduce
Compare the output of the following two commands:
docker run --rm -it --platform linux/arm64 ubuntu bash -c 'exec 0<&- "$@"' bash perl -ne 'print;'docker run --rm -it --platform linux/amd64 ubuntu bash -c 'exec 0<&- "$@"' bash perl -ne 'print;'
Compare the output of the following two commands:
docker run --rm -it --platform linux/arm64 python bash -c 'exec 0<&- "$@"' bash python -c 'import sys; sys.stdin.buffer.seek(0); print(sys.stdin.buffer.read(1024))'docker run --rm -it --platform linux/amd64 python bash -c 'exec 0<&- "$@"' bash python -c 'import sys; sys.stdin.buffer.seek(0); print(sys.stdin.buffer.read(1024))'
Expected behavior
Stdin/fd 0 should not be open or readable
docker version
Client:
Version: 28.5.2
API version: 1.51
Go version: go1.25.3
Git commit: ecc6942
Built: Wed Nov 5 14:42:30 2025
OS/Arch: darwin/arm64
Context: desktop-linux
Server: Docker Desktop 4.53.0 (211793)
Engine:
Version: 29.0.1
API version: 1.52 (minimum version 1.44)
Go version: go1.25.4
Git commit: 198b5e3
Built: Fri Nov 14 16:18:20 2025
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: v2.1.5
GitCommit: fcd43222d6b07379a4be9786bda52438f0dd16a1
runc:
Version: 1.3.3
GitCommit: v1.3.3-0-gd842d771
docker-init:
Version: 0.19.0
GitCommit: de40ad0docker info
Client:
Version: 28.5.2
Context: desktop-linux
Debug Mode: false
Plugins:
ai: Docker AI Agent - Ask Gordon (Docker Inc.)
Version: v1.13.0
Path: /Users/pip/.docker/cli-plugins/docker-ai
buildx: Docker Buildx (Docker Inc.)
Version: v0.29.1-desktop.1
Path: /Users/pip/.docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.40.3-desktop.1
Path: /Users/pip/.docker/cli-plugins/docker-compose
debug: Get a shell into any image or container (Docker Inc.)
Version: 0.0.45
Path: /Users/pip/.docker/cli-plugins/docker-debug
desktop: Docker Desktop commands (Docker Inc.)
Version: v0.2.0
Path: /Users/pip/.docker/cli-plugins/docker-desktop
extension: Manages Docker extensions (Docker Inc.)
Version: v0.2.31
Path: /Users/pip/.docker/cli-plugins/docker-extension
init: Creates Docker-related starter files for your project (Docker Inc.)
Version: v1.4.0
Path: /Users/pip/.docker/cli-plugins/docker-init
mcp: Docker MCP Plugin (Docker Inc.)
Version: v0.28.0
Path: /Users/pip/.docker/cli-plugins/docker-mcp
model: Docker Model Runner (Docker Inc.)
Version: v1.0.0
Path: /Users/pip/.docker/cli-plugins/docker-model
offload: Docker Offload (Docker Inc.)
Version: v0.5.24
Path: /Users/pip/.docker/cli-plugins/docker-offload
pass: Docker Pass Secrets Manager Plugin (beta) (Docker Inc.)
Version: v0.0.11
Path: /Users/pip/.docker/cli-plugins/docker-pass
sandbox: Docker Sandbox (Docker Inc.)
Version: v0.6.0
Path: /Users/pip/.docker/cli-plugins/docker-sandbox
sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
Version: 0.6.0
Path: /Users/pip/.docker/cli-plugins/docker-sbom
scout: Docker Scout (Docker Inc.)
Version: v1.18.3
Path: /Users/pip/.docker/cli-plugins/docker-scout
Server:
Containers: 3
Running: 0
Paused: 0
Stopped: 3
Images: 11
Server Version: 29.0.1
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: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
CDI spec directories:
/etc/cdi
/var/run/cdi
Discovered Devices:
cdi: docker.com/gpu=webgpu
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: fcd43222d6b07379a4be9786bda52438f0dd16a1
runc version: v1.3.3-0-gd842d771
init version: de40ad0
Security Options:
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.12.54-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: aarch64
CPUs: 14
Total Memory: 7.653GiB
Name: docker-desktop
ID: bd45d0e1-280a-4205-b0e6-a8f0a8af4a00
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
Labels:
com.docker.desktop.address=unix:///Users/pip/Library/Containers/com.docker.docker/Data/docker-cli.sock
Experimental: false
Insecure Registries:
hubproxy.docker.internal:5555
::1/128
127.0.0.0/8
Live Restore Enabled: falseDiagnostics ID
AB5A849A-CE72-4BA8-9C05-AC09CE2E4C99/20251129094534
Additional Info
No response