Docker Community Forums

Share and learn in the Docker community.

Docker run exits immediately despite --detach, --interactive, --tty, and providing a command

On a Windows 10 host, Docker version 19.03.13, build 4484c46d9d, I tried running a docker image with all possible combinations of --tty, --interactive, and --detach, but none of them brings me to a bash prompt, always exiting immediately. /bin/bash is present in the image. The Dockerfile is from https://hub.docker.com/r/astj/centos5-vault/dockerfile

I ran:
docker run <switches> astj/centos5-vault /bin/bash
where <switches> had been exercised with the full set of -t, -i, -d combinations, namely:
-d, -i, -t, -it, -id, -td, -dit

In all cases, the container exits immediately.
If I change /bin/bash to ls, I can see a directory listing. But of course, the container exits immediately as expected. To troubleshoot, I experimented with the following entry commands on the astj/centos5-vault image, with these docker switches. All of them exit immediately:

docker run <switches> astj/centos5-vault <entry_command>:
+----------+---------------------+---------------------------------------+
| Switches |    Entry command    |                Output                 |
+----------+---------------------+---------------------------------------+
|          | /bin/bash           | None. Exits.                          |
| -i       | /bin/bash           | None. Exits.                          |
| -it      | /bin/bash           | None. Exits.                          |
| -t       | /bin/bash           | None. Exits.                          |
| -td      | /bin/bash           | Prints a container hash, exits.       |
| -id      | /bin/bash           | Prints a container hash, exits.       |
| -d       | /bin/bash           | Prints a container hash, exits.       |
| -dit     | /bin/bash           | Prints a container hash, exits.       |
| -it      | ls -la /bin/bash    | Lists bash file info*, exits.         |
| -it      | /bin/bash --version | None. Exits.                          |
| -it      | /bin/bash --login   | None. Exits.                          |
| -it      | /bin/uname -r       | "4.19.128-microsoft-standard". Exits. |
|          | whoami              | "root". Exits.                        |
+----------+---------------------+---------------------------------------+
*Listed bash file info is: -rwxr-xr-x 1 root root 768664 Jul 10  2013 /bin/bash

I tried to troubleshoot but docker logs <container> doesn’t show a single line of log.

Does anyone know why the /bin/bash command still causes the container to exit immediately instead of bringing me to a bash prompt?

I guess the problem is that the windows terminal will not open a terminal. In linux, your -it line works as expected. Have you tried to wrap it with winpty (not sure if this is part of windows or git for windows)?

I can get to a terminal with another image though (e.g. alpine). It may be something related to the astj/centos5-vault image, or docker itself, but I am out of ideas how to troubleshoot this.