πŸ™‡ Docker Commands Reference

🎯 Basic Commands

CommandDescription
docker build -t [tagName] .Building the Docker Image πŸ“¦ from Dockerfile
docker run [ImageName]Pulls the image (if not present) and runs the container
docker psLists all running containers (process status)
docker stop [containerID/containerName]Stops a running container
docker ps -aLists all containers, including stopped ones
docker rm [containerID/containerName]Removes a container permanently
docker imagesLists all downloaded images with size and Image ID
docker image inspect kodekloud/simple-webapp-mysqlShows detailed information about an image
docker rmi [imageName/imageID]Removes an image (Note: Remove dependent containers first)
docker pull [image:version]Pulls the specified image from Docker Hub

⚑ Advanced Commands

CommandDescription
docker stop $(docker ps -a -q)Stops all containers
docker rm $(docker ps -a -q)Removes all containers
docker stop sd pr msStops multiple containers (e.g., sd, pr, and ms)
docker rmi $(docker images -q)Removes all images

πŸ› οΈ Accessing the Container Terminal

CommandDescription
docker run -it centos bashLaunches a CentOS container and opens the Bash shell (-it stands for interactive mode)
cat /etc/*release*Shows the OS version inside the container

πŸ’‘ Command Tips

  • Use -it for interactive mode when you need to access the container’s shell
  • Use -d to run containers in detached mode (background)
  • Use -p to map ports from container to host
  • Use -v to mount volumes for persistent data
  • Use --name to assign custom names to containers for easier management