🐳 Docker Command Cheat Sheet
🐳 Docker Command Cheat Sheet 🔢 Basic Docker Commands 1 .docker –version Use Case: Verify Docker installation and version. Example: docker –version Output: Docker version 24.0.5, build ced0996 2. docker info Use Case: Display system-wide information about Docker installation. Example: docker info Output: Containers: 3Running: 1Paused: 0Stopped: 2Images: 10… 3. docker help Use Case: List available Docker commands and options. Example: docker help Output: Usage: docker [OPTIONS] COMMAND … 🚀 Container Management 1. docker ps Use Case: List running containers. Example: docker ps Output: CONTAINER ID IMAGE COMMAND STATUS NAMESabc123 nginx … Up 5s mynginx 2.docker ps -a Use Case: List all containers, including stopped ones. Example: docker ps – a Output: CONTAINER ID IMAGE COMMAND STATUS NAMESabc123 nginx … Exited (0) 2 minutes ago mynginx 3. docker stop < container_id > Use Case: Stop a running container. Example: docker stop abc123 Output: abc123 4. docker start < container_id > Use Case: Start a previously stopped container. Example: docker start abc123 Output: abc123 5. docker restart < container_id > Use Case: Restart a container (stop and start). Example: docker restart abc123 Output: abc123 6. docker rm < container_id > Use Case: Remove a stopped container from the system. Example: docker rm abc123 Output: abc123 7. docker logs < container_id > Use Case: View logs for a container. Example: docker logs abc123 Output: Starting nginx… Ready to serve requests 8. docker exec -it < container_id > bash Use Case: Access the shell of a running container. Example: docker exec -it abc123 bash Output: root@abc123:/# 🌀 Image Management 1. docker images Use Case: List all Docker images available locally. Example: docker images Output: REPOSITORY TAG IMAGE ID CREATED SIZEnginx latest abcdef123456 3 days ago 133MB 2. docker pull < image_name > Use Case: Download an image from Docker Hub. Example: docker pull nginx Output: Using default tag: latestlatest: Pulling from library/nginx…Digest: sha256:…Status: Downloaded newer image for nginx:latest 3. docker rmi < image_name > Use Case: Remove a local Docker image. Example: docker rmi nginx Output: Untagged: nginx:latestDeleted: sha256:… 4. docker build – t < image_name > . Use Case: Build a Docker image from a Dockerfile. Example: docker build -t myapp . Output: Successfully built abcdef123456Successfully tagged myapp:latest 🛠️ Running Containers 1. docker run < image_name > Use Case: Run a container from an image. Example: docker run nginx Output: … (nginx process logs) 2. docker run -d < image_name > Use Case: Run a container in the background (detached mode ). Example: docker run -d nginx Output: abc123456789… 3. docker run –name < name > < image > Use Case: Assign a name to the container Example: docker run –name mynginx nginx Output: … (container output) 4. docker run -p 8080:80 < image > Use Case: Expose a container port to the host. Example: docker run -p 8080:80 nginx Output: … (nginx running and accessible at localhost:8080) 5. docker run -v /host/path:/container/path < image > Use Case: Mount host directory into the container. Example: docker run -v /tmp:/data nginx Output: … (container starts and has access to /data) 6. docker run –rm < image > Use Case: Automatically remove the container once it stops. Example: docker run –rm hello-world Output: Hello from Docker! … 🌐 Networking 1. docker network ls Use Case: List all Docker networks. Example: docker network ls Output: NETWORK ID NAME DRIVER SCOPEabc123 bridge bridge local . . . 2.docker network create < network_name > Use Case: Create a new custom network. Example: docker network create mynet Output: mynet 3. docker network inspect < network_name > Use Case: Inspect detailed information about a network. Example: docker network inspect mynet Output: [ { “Name”: “mynet”, “Id”: “…”, “Containers”: {}, … }] 4. docker network connect < network_name > < container_name > Use Case: Connect a container to a network. Example: docker network connect mynet mynginx Output: (no output if successful) 5. docker network disconnect <network_name> <container_name> Use Case: Disconnect a container from a network. Example: docker network disconnect mynet mynginx Output: (no output if successful) 📁 Volumes & Storage 1. docker volume ls Use Case: List all docker volumes Example: docker volume ls Output: DRIVER VOLUME NAMElocal myvolume 2. docker volume create < volume_name > Use Case: Create a new volume Example: docker volume create myvolume Output: myvolume 3. docker volume inspect < volume_name > Use Case: View detailed info about a volume. Example: docker volume inspect myvolume Output: [ { “Name”: “myvolume”, “Driver”: “local”, … }] 4. docker volume rm < volume_name > Use Case: Delete a Volume Example: docker volume rm myvolume Output: myvolume 📄 Docker Compose 1. docker-compose up Use Case: Start services defined in a docker-compose.yml. Example: docker-compose up Output: Starting myapp … done… 2. docker-compose up -d Use Case:Start services in detached mode. Example: docker-compose up -d Output: Creating network “myapp_default” with the default driverCreating myapp … done 3. docker-compose down Use Case: Stop and remove all services and resources created by Compose. Example: docker-compose down


