Docker Cheat-Sheet for Beginners 🐳

Are you new to Docker and looking for a quick reference guide? This beginner-friendly cheat sheet will help you get started with essential Docker commands for container management, images, and networking.

🔧 Common Docker Commands

  1. Start Docker:
    • Linux: systemctl start docker
    • macOS: open -a Docker
  2. Check Docker Version:
    • docker --version

📦 Working with Containers

  1. List Running Containers: docker ps
  2. List All Containers: docker ps -a
  3. Run a Container: docker run <image_name>
  4. Run Detached: docker run -d <image_name>
  5. Run with Port Mapping: docker run -p <host_port>:<container_port> <image_name>
  6. Stop a Container: docker stop <container_id>
  7. Restart a Stopped Container: docker start <container_id>
  8. Remove a Container: docker rm <container_id>

📜 Image Management

  1. List Images: docker images
  2. Pull an Image: docker pull <image_name>
  3. Build from Dockerfile: docker build -t <image_name> .
  4. Tag an Image: docker tag <image_id> <new_image_name>:<tag>
  5. Remove an Image: docker rmi <image_id>

🔄 Managing Containers

  1. View Logs: docker logs <container_id>
  2. Access Container Shell: docker exec -it <container_id> /bin/bash
  3. Copy Files to Host: docker cp <container_id>:<path_inside_container> <host_path>

🏗 Docker Networks

  1. List Networks: docker network ls
  2. Create Network: docker network create <network_name>
  3. Connect Container to Network: docker network connect <network_name> <container_id>

🐳 Docker Compose

  1. Start Services in Detached Mode: docker-compose up -d
  2. Stop Services: docker-compose down
  3. Build & Start Containers: docker-compose up --build

📊 Inspecting & Monitoring

  1. Inspect Container: docker inspect <container_id>
  2. Display Resource Usage: docker stats

🛠 Volumes

  1. List Volumes: docker volume ls
  2. Create Volume: docker volume create <volume_name>
  3. Mount Volume: docker run -v <volume_name>:<path_inside_container> <image_name>

Use this guide as a quick reference to keep your Docker workflow smooth and efficient. Happy containerizing! 🐋

Comments