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
wow, thanks. I was struggling with this. your notes really helped.