Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker compose run hangs indefinitely if stdout/err were duplicated to a file #8908

Closed
chadwhitacre opened this issue Nov 9, 2021 · 5 comments · Fixed by #9035
Closed

docker compose run hangs indefinitely if stdout/err were duplicated to a file #8908

chadwhitacre opened this issue Nov 9, 2021 · 5 comments · Fixed by #9035

Comments

@chadwhitacre
Copy link

chadwhitacre commented Nov 9, 2021

Description

We have a self-hosted repo where we provide a Dockerized version of our application for small installs. Our install script for this repo is fairly involved, and one of the things we do is capture stdout/stderr in a file to aid in debugging installation issues:

exec &> >(tee -a "$log_file")

Straightforward enough, and it works fine with Docker Compose v1.

With Docker Compose v2, we're seeing that— following the logging capture—a docker compose run invocation that prompts for input will hang indefinitely, and can't be killed with Ctrl-C either. I've whittled down a test case.

Steps to reproduce the issue:

  1. Clone https://github.com/chadwhitacre/docker-compose-v2-tty-bug/.
  2. Ensure which docker-compose resolves to Docker Compose v1.
  3. Ensure which docker resolves to a Docker with Compose v2.
  4. ./test.sh

Describe the results you received:

The test script accepts three prompts, then hangs.

$ ./test.sh
[+] Running 2/2
 ⠿ Container tty-test_testing_run_397b9b93f30e  Removed                                                   0.0s
 ⠿ Network tty-test_default                     Removed                                                   0.1s
[+] Building 0.1s (8/8) FINISHED                                                                               
 => [internal] load build definition from Dockerfile                                                      0.0s
 => => transferring dockerfile: 31B                                                                       0.0s
 => [internal] load .dockerignore                                                                         0.0s
 => => transferring context: 2B                                                                           0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                          0.0s
 => [1/3] FROM docker.io/library/ubuntu:latest                                                            0.0s
 => [internal] load build context                                                                         0.0s
 => => transferring context: 34B                                                                          0.0s
 => CACHED [2/3] WORKDIR /app                                                                             0.0s
 => CACHED [3/3] COPY ./entrypoint.sh /app                                                                0.0s
 => exporting to image                                                                                    0.0s
 => => exporting layers                                                                                   0.0s
 => => writing image sha256:f56005f2b65454c8f5ea738a6caf0237f4727243937d75a7424d45ef2592ced2              0.0s
 => => naming to docker.io/library/tty-test_testing                                                       0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Creating network "tty-test_default" with the default driver
Creating tty-test_testing_run ... 
Creating tty-test_testing_run ... done
Program: foo
Greetings, foo!
Program: bar
Greetings, bar!
Creating tty-test_testing_run ... 
Creating tty-test_testing_run ... done
Program: baz
Greetings, baz!
Aaaaaaaaaaaaaaand ...

Describe the results you expected:

The test script accepts four prompts, then exits cleanly.

Output of docker compose version:

$ docker compose version
Docker Compose version v2.0.0
$ docker-compose --version
docker-compose version 1.29.2, build 5becea4c
$

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Build with BuildKit (Docker Inc., v0.6.3)
  compose: Docker Compose (Docker Inc., v2.0.0)
  scan: Docker Scan (Docker Inc., v0.8.0)

Server:
 Containers: 3
  Running: 2
  Paused: 0
  Stopped: 1
 Images: 29
 Server Version: 20.10.8
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  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 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: e25210fe30a0a703442421b0f60afac609f950a3
 runc version: v1.0.1-0-g4144b63
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.10.47-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.64GiB
 Name: docker-desktop
 ID: LNAI:QCLJ:TERN:UEWD:TS3G:M63J:OH2W:FFX7:FTNM:7WZL:7QUE:EIPU
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
@chadwhitacre
Copy link
Author

@ndeloof @ulyssessouza Any chance you could triage this issue? 🙇‍♂️

@ulyssessouza
Copy link
Collaborator

Hello @chadwhitacre.

Thank you for reporting this issue and the test case. This helps a lot to understand the problem.

Actually it doesn't hang. What happens is that the output asking for the entry is not printed.
If you type something and hit Return it should work as expected. That's more a problem on the output other than the very program flow...
I'll keep on debugging... Please tell me if this hint rings any bell for you...

@chadwhitacre
Copy link
Author

Thanks for taking a look @ulyssessouza. If I type something and hit Return after seeing the "Aaaaaaaaaaaaaaand ..." output (i.e., where the fourth prompt should be), I don't seem to get anywhere. I never get a prompt back and the docker process continues to run. Here's a video of what I'm seeing (yes I'm bashing away on the keyboard while the "Aaaaaaaaaaaaaaand ..." is up ;):

repro.mp4

@ndeloof
Copy link
Contributor

ndeloof commented Dec 10, 2021

tested on recent codebase:

docker-compose run --rm testing
Program: hello
Greetings, hello!

I guess this has been fixed already! could you please confirm?

@chadwhitacre
Copy link
Author

@ndeloof The repro you show doesn't include the stdout/err redirect from the test case. Did you test it with that?

could you please confirm?

With a newer version of Docker Compose, 2.2.1 vs. 2.0.0, I get @ulyssessouza's result, where stdout (err?) is not displayed to the user but stdin still works. That's better! :) How to get stdout/err, though? 🤔

My repro results with 2.2.1
/Users/chadwhitacre/workbench/chadwhitacre/docker-compose-v2-tty-bug
total 8
drwxr-xr-x  4 chadwhitacre  staff  128 Dec 13 15:49 app/
-rw-r--r--  1 chadwhitacre  staff   38 Dec 13 15:49 docker-compose.yml
-rwxr-xr-x  1 chadwhitacre  staff  526 Dec 13 15:49 test.sh*
$ 
$ 
$ docker-compose version
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1h  22 Sep 2020
$ 
$ 
$ docker compose version
Docker Compose version v2.2.1
$ 
$
$ $ ./test.sh 
[+] Running 2/0
 ⠿ Container docker-compose-v2-tty-bug_testing_run_08308bccc34e  Removed                              0.0s
 ⠿ Network docker-compose-v2-tty-bug_default                     Removed                              0.0s
[+] Building 0.1s (8/8) FINISHED                                                                           
 => [internal] load build definition from Dockerfile                                                  0.0s
 => => transferring dockerfile: 123B                                                                  0.0s
 => [internal] load .dockerignore                                                                     0.0s
 => => transferring context: 2B                                                                       0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                      0.0s
 => [internal] load build context                                                                     0.0s
 => => transferring context: 110B                                                                     0.0s
 => [1/3] FROM docker.io/library/ubuntu:latest                                                        0.0s
 => CACHED [2/3] WORKDIR /app                                                                         0.0s
 => CACHED [3/3] COPY ./entrypoint.sh /app                                                            0.0s
 => exporting to image                                                                                0.0s
 => => exporting layers                                                                               0.0s
 => => writing image sha256:f56005f2b65454c8f5ea738a6caf0237f4727243937d75a7424d45ef2592ced2          0.0s
 => => naming to docker.io/library/docker-compose-v2-tty-bug_testing                                  0.0s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Creating network "docker-compose-v2-tty-bug_default" with the default driver
Creating docker-compose-v2-tty-bug_testing_run ... 
Creating docker-compose-v2-tty-bug_testing_run ... done
Program: foo
Greetings, foo!
Program: bar
Greetings, bar!
Creating docker-compose-v2-tty-bug_testing_run ...
Creating docker-compose-v2-tty-bug_testing_run ... done
Program: baz
Greetings, baz!
Aaaaaaaaaaaaaaand ...
buz
Greetings, buz!
$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants