Basic Docker Commands | Perfect for beginners

Image for post
Image for post

Basic docker commands for beginners

docker version
docker info

Docker commands — Images

docker search <<imagename>> | head -20docker search ubuntu | head -20
# will search ubuntu images in the dockerhub and limit the search result to only 20
docker search ubuntu | select -first 10
docker pull <<imagename>>
docker pull nginx
docker history <<imagename>>
docker history nginx
docker pull <<imagename>>:<<versiontag>>
docker pull busybox:1.24
docker images
docker rmi <<imagename>>
docker rmi nginx
docker run <<imagename>>
docker run --name cntnginx -d nginx
# --name to specify a name for the running container. In this example, it is cntnginx
# -d to run the container in background (detached mode)

Docker Commands — Containers

docker ps
docker ps -a
docker inspect <<containername/containerid>>
docker inspect cntnginx
docker stats <<containername/containerid>>
docker stats cntnginx
docker pause <<containername/containerid>>
docker pause cntnginx
docker unpause <<containername/containerid>>
docker unpause cntnginx
docker kill <<containername/containerid>>
docker kill cntnginx
docker start <<containername/containerid>>
docker start cntnginx
docker stop <<containername/containerid>>
docker stop cntnginx
docker rm <<containername/containerid>>
docker rm cntnginx
docker container prune
docker export <<containername/contianerid>> -o <<filename>>.tar
docker run --name newnginxcontainer -d nginx
docker export newnginxcontainer -o test.tar

# Note: You must have permissions on the folder where you are saving the test.tar
# use `chmod 777 ./` for permissions in case if you are facing an permission denied error.
docker import <<remoteurl/imagename.tar>>
docker import test.tar

Digital Enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store