Docker Commands

Reference Guide & Cheat Sheet

⚙️ Setup & Status

yum install docker -y / yum install git -y
docker -v
-->> Docker version 25.0.14, build 0bab007
systemctl start docker
-->> To Start Docker || ps -ef | grep docker
systemctl stop docker
-->> To Stop Docker
systemctl status docker
-->> To Check Docker Status

📦 Container Lifecycle

docker start <container-name>
-->> To START Container
docker stop <container-name>
-->> To STOP Container
docker restart <container-name>
-->> To RE-START Container
docker run -it --name <container-name> <image name>
docker run -it -d --name <container-name> <image name>
-->> 'D', means detach...
docker exec -it <container-name> /bin/bash/span>
-->> (Enter in to the Container) like ., /opt/tomcat/bin

🔍 Monitor & Inspect

docker ps
-->> To Check the Process || CONTAINER ID IMAGE COMMAND CREATD STATUS PORTS NAMES
docker ps -a
-->> To Check Status of Running Containers || CONTAINER ID IMGE COMMAND CREATED STATUS PORTS NAMES
docker top <container-name>
-->> To Check the Process
docker logs <container-name>
-->> To Check the Logs ., like ., /opt/tomcat/logs

🖼️ Images & Building

docker images
-->> To Check the Images Available || REPOSITORY TAG IMAGE IDCREATED SIZE
docker pull krishnabank: latest
-->> If we give exact TAG, it will pull only that Image from Online DockerHub)
docker pull krishnabank
-->> If we don't give TAG, it will only pull available LatestImage from (Online DockerHub)
docker build -t <image-name-TAG> .
-->> TO BUILD OUR OWN IMAGE (FIRST CREATE NEW DOCKER FILE, THN BUILD NEW IMAGE ,)
docker run -d -p 8080:8080 --name <container-name> <image-name-TAG>

🗑️ Cleanup

If we have then we can RUN IN CONTAINER.. WITHOUT IMAGE NO CONTAINER
If it's running container, we can't directly remove container
-->> Container -> remove first // Image -> remove after
docker rm <container-name> // docker rm -f <container-name>
// Before removing checking -->>
docker rmi -f <image-name> // docker rmi -f <container-name> <image-nme> // docker rm -f $(docker ps -aq) // docker rmi -f $(docker images -q)
docker rm $(docker ps -aq)

🌐 Files & Network

docker cp test.txt <container-name>:/opt/
-->> Host -> Container (Copy test.txt from host -> into contaner /opt)
docker cp <container-name>:/opt/file.txt .
-->> Container -> Host (Copy file from container -> to curren directory)
Port Mapping -p 8081:8080
-->> (EC2) Host -->> 8081 // Cntainer -> 8080
cat>Dockerfile // touch Dockerfile
-->> To Create the Dockerfile
vim Dockerfile
-->> To Edit Dockerfile use vim q! – quite without save :wq! –save and quite

🛠️ Utilities & Deployments

yum install wget -y / yum install findutils -y / yum install tar -y / yum install gzp -y / yum install httpd -y / yum install maven -y / yum update -y
-->> To Check the Status of Application , without checking inBrower.. (IP As per your IP-Host)