Docker Commands You Must Know – Quick Guide for Beginners
Essential Docker Commands – Quick Reference Guide
A concise collection of commonly used Docker commands with one-line explanations, designed for quick revision, daily usage, and interview preparation.
docker --version # shows Docker version
docker version # shows client and server version info
docker ps # lists running containers
docker ps -a # lists all containers
docker container ls # lists running containers (modern syntax)
docker container ls -a # lists all containers (modern syntax)
docker images # lists all Docker images
docker image ls # alternative command to list images
docker images -q # shows only image IDs
docker pull ubuntu # pulls ubuntu:latest image from registry
docker pull ubuntu:22.04 # pulls specific image tag
docker run ubuntu # creates and runs a container
docker run -it ubuntu bash # creates interactive container with shell
docker run -it --name cont1 ubuntu bash # creates and runs named container
docker run -d ubuntu sleep infinity # runs container in background
docker create ubuntu # creates container without starting
docker start cont1 # starts a stopped container
docker start -i cont1 # starts container and attaches terminal
docker ps -q # shows running container IDs
docker ps -aq # shows all container IDs
docker exec -it cont1 bash # opens a new shell inside running container
docker attach cont1 # attaches to main container process
docker stop cont1 # gracefully stops container
docker kill cont1 # force stops container
docker pause cont1 # pauses container processes
docker unpause cont1 # resumes paused container
docker rm cont1 # removes stopped container
docker rm -f cont1 # force removes running container
docker rm -f $(docker ps -aq) # removes all containers
docker rmi image_name # removes an image
docker rmi -f image_name # force removes an image
docker rmi -f $(docker images -aq) # removes all images
docker image prune # removes unused images
docker container prune # removes stopped containers
docker system prune # removes unused containers, images, networks
docker build -t myimage . # builds image from Dockerfile
docker commit cont1 myimage:v1 # creates image from container state
apt update # updates package lists inside container
apt install -y python3 # installs Python 3 inside container
apt install -y apache2 # installs Apache inside container
apt install -y mysql-server # installs MySQL inside container
apachectl -D FOREGROUND # starts Apache in foreground
service apache2 start # starts Apache service
Comments
Post a Comment