Docker Basic Commands. PS Cheat Sheet Ep-01
Hi Friends, I hope you guys are doing well.

So today we are going do our hands dirty with docker commands.
*** Lets Start ***
- Create a container of ubuntu OS using this one simple command
# docker run ubuntu:latestUnable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
da7391352a9b: Pull complete
14428a6d4bcd: Pull complete
2c2d948710f2: Pull complete
Digest: sha256:c95a8e48bf88e9849f3e0f723d9f49fa12c5a00cfc6e60d2bc99d87555295e4c
Status: Downloaded newer image for ubuntu:latest
- To check if the earlier image is present or not, use this command to see the images present on host
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest f643c72bc252 2 weeks ago 72.9MB
hello-world latest bf756fb1ae65 11 months ago 13.3kB
since we did specify tag name as latest , the latest image from the registry was pulled.
Alternatively you can also you docker pull command to download it , then docker run command to enter the container.
- To login to the container , or run the container, follow with me
# docker run -it ubuntu bash
root@f85d1c4294c5:/#
root@f85d1c4294c5:/# ls
bin boot dev etc home lib lib32 lib64 libx32 media mnt opt proc root run sbin srv sys tmp usr var
root@f85d1c4294c5:/#
The catch here is, once you exit the container, the container also exists, meaning the container is killed. You can see the history using docker ps -a
- Check the containers running in your docker host. This will show only if the container is not exited.
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
719ef0c96e36 ubuntu:latest “bash” About a minute ago Up 3 seconds keen_kare
- Check the list of docker ever ran on the docker host, it also shows the image used for that container and the command used while running it.
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
719ef0c96e36 ubuntu:latest “bash” 3 minutes ago Up 2 minutes keen_kare
a13e732833e6 ubuntu “/bin/bash” 5 minutes ago Exited (0) 5 minutes ago nervous_nightingale
1ada3cb24eb7 hello-world “/hello” 2 days ago Exited (0) 2 days ago modest_lederberg
- Start a container which was exited earlier. for example lets start our hello-world container which exited 2 days ago
1ada3cb24eb7 hello-world “/hello” 2 days ago Exited (0) 2 days ago modest_lederberg# docker start 1ada3cb24eb7
1ada3cb24eb7
Alternatively you can also give container name i.e. modest_lederberg in our example.
- If you want to log-in to the container and exit without killing the container, follow with me
# docker attach 1ada3cb24eb7
root@f85d1c4294c5:/# ls
bin boot dev etc home lib lib32 lib64 libx32 media mnt opt proc root run sbin srv sys tmp usr var
root@f85d1c4294c5:/#
Once attached , press ctrl+p & ctrl+q you will exit the container without killing it :D
# docker attach 1ada3cb24eb7
root@f85d1c4294c5:/# read escape sequence
admin@admin:/mnt/c/Users/admin# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1ada3cb24eb7 ubuntu “bash” 8 minutes ago Up 2 minutes
modest_lederberg
admin@admin:/mnt/c/Users/admin#
That’s all for today, I hope you learnt to play around with container, Next up we will learn about image commands in docker.
Please take a minute to appreciate your efforts. You made it. Learnt something new. :) Congratulations
Article 1 : Hello World Docker
Article 2 : Docker Terminologies
Follow me on linkedin,
Stay tuned , Keep Learning. Cheers :D