skip to Main Content

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


  1. 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:

    $ docker create --name foobar -it mcr.microsoft.com/dotnet/aspnet:6.0-alpine
    $ docker container start --interactive foobar
    

    otherwise you can run it directly:

    $ docker run --name foobar -it mcr.microsoft.com/dotnet/aspnet:6.0-alpine
    
    Login or Signup to reply.
  2. 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:

    docker run --name dotnet mcr.microsoft.com/dotnet/aspnet:6.0-alpine
    
    # and then check the dotnet container
     docker ps -a | grep dotnet
    

    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:

    docker run --rm --name dotnet -it mcr.microsoft.com/dotnet/aspnet:6.0-alpine sh
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search