When running:
docker-compose up -d
docker-compose exec test echo hello > /dev/null 2> /dev/null
where docker-compose.yml
is:
version: "3.9"
services:
test:
image: ubuntu
command: tail -f /dev/null
the terminal still displays:
hello
while I would expect it to display nothing (since both stdout and stderr are redirected to /dev/null).
How can a program display anything on the terminal without going through stdout/stderr?
EDIT: There seems to be an issue opened on docker-compose: https://github.com/docker/compose/issues/9104
The issue is not present with docker-compose v1:
docker-compose-v1 exec test echo hello > /dev/null
outputs nothing.
The issue is not present when forcing not to use a pseudo-tty:
docker-compose exec -T test echo hello > /dev/null
outputs nothing.
The issue is not present when using docker
directly:
docker run ubuntu echo hello > /dev/null
outputs nothing.
Even when forcing the use of a pseudotty:
docker run -it ubuntu echo hello > /dev/null
$ docker version
Client:
Cloud integration: v1.0.22
Version: 20.10.12
API version: 1.41
Go version: go1.16.12
Git commit: e91ed57
Built: Mon Dec 13 11:46:56 2021
OS/Arch: darwin/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.16.12
Git commit: 459d0df
Built: Mon Dec 13 11:43:56 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
$ docker-compose version
Docker Compose version v2.2.3
OS = macOS 11.6.3
I believe this has been fixed. I have just tested it with docker-compose version 2.6.1 and it doesn't show any output.
❯ docker-compose up --build --force-recreate -d
[+] Running 2/2
⠿ Network docker-test_default Created 0.1s
⠿ Container docker-test-test-1 Started 0.5s
❯ docker-compose exec test echo hello > /dev/null 2> /dev/null
❯ docker version
Client:
Cloud integration: v1.0.24
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:04:45 2022
OS/Arch: darwin/arm64
Context: default
Experimental: true
Server: Docker Desktop 4.10.1 (82475)
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
Built: Mon Jun 6 23:01:01 2022
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.6
GitCommit: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc:
Version: 1.1.2
GitCommit: v1.1.2-0-ga916309
docker-init:
Version: 0.19.0
GitCommit: de40ad0
❯ docker-compose version
Docker Compose version v2.6.1
❯
MacOs = 12.3.1 ; M1 processor
As a side note, Docker-compose v2 has been made Generally Available on late April 2022