Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save munim/e627ad2316d23971883e6dde210231de to your computer and use it in GitHub Desktop.
Save munim/e627ad2316d23971883e6dde210231de to your computer and use it in GitHub Desktop.
Start a stopped docker container in bash/shell interactive mode

Start a stopped docker container in bash/shell interactive mode

For instance, you have just pulled a CentOS or Ubuntu image using docker pull centos:latest or docker pull ubuntu:latest.

Your immediate command would be

# docker run -it centos:latest
# docker ps -a

Please note that -it is very important for /bin/bash to run and then exit.

And you will see that your docker container stopped. You will want to start the container and get into a bash prompt.

You'll need to get the container ID or name using the following command

# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
fc9776797af5        centos:latest       "/bin/bash"         8 minutes ago       Exited (127) 4 seconds ago                       stoic_ramanujan

And then run the following command to get an interactive bash shell in your container

# docker start -ai stoic_ramanujan  
@aahnik
Copy link

aahnik commented Apr 1, 2021

wow, thanks. I was struggling with this. your notes really helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment