In Docker on Windows, I have pulled the image mcr.microsoft.com/dotnet/aspnet:6.0-alpine
. I now have a container based on this image. I want to start this image and run shell commands on it. But whenever I start the container, it exits immediately.
I have tried starting it from the Docker Desktop GUI and from the command line:
docker start <container-name>
docker container start <container-name>
docker container start <container-name> -i
docker container start <container-name> --interactive
All lead to the same result: It exits immediately with no error message and no logs.
I am not very good at Docker, so the solution may be super-obvious. I just haven’t been able to find it.
2
Answers
You need to make sure to allocate a pseudo-TTY connected to the container’s stdin (and this must be before the image name, as all docker options come before it)
So if you want to create the container and use it later:
otherwise you can run it directly:
So you start the container by using
docker start ...
and the reason for which your container is not running is because there’s no process running in your container, more exactly if you do:You’re going to see that the process in the container has run and finished successfully
Exited (0) 2
Now, in order to have the container running you can spin up an interactive terminal when you start the container:
One thing to mention is that as soon as you stop/exit the interactive session, your container stops running because once again there’s no process running in the container.