How to Start an Interactive Docker Container

Sometimes when working with Docker you just want to quickly start a container and interact with it through a shell. Fortunately this is easy to do. Here is an example of creating and running an Ubuntu container with a bash shell:

docker run -it --rm ubuntu /bin/bash

Here is the explanation of this command:

docker run – run a command in a Docker container
-t – allocate a psuedo tty (terminal)
-i – keep STDIN open in order to interact with the terminal
--rm – remove/delete the container once it exits (optional)
ubuntu – create the container from the latest Ubuntu image
/bin/bash – start a bash shell session

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">