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.

Did you ever get to the bottom of this? I’m having an identical problem with a slightly different environment. Windows 10, but running docker inside fedora under WSL2. My container is RHEL 6.10 and my result is the same, exits immediately. Other containers are fine - RHEL 7.6 gives me a bash terminal. I had the same docker version as you, so I updated to 20.10.2 but the problem persists.

For anyone finding their way here later, in my configuration mentioned above this was an issue specific to Windows environments which was resolved with a change in Windows 10 Build 18995.

Steps to resolve:

  1. Create file : %userprofile%.wslconfig
  2. Add this two lines :
    [wsl2]
    kernelCommandLine = vsyscall=emulate
  3. Restart wsl
    wsl --shutdown
  4. Restart Docker Desktop

I found the answer here: