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
- Start Docker:
- Linux:
systemctl start docker - macOS:
open -a Docker
- Linux:
- Check Docker Version:
docker --version
📦 Working with Containers
- List Running Containers:
docker ps - List All Containers:
docker ps -a - Run a Container:
docker run <image_name> - Run Detached:
docker run -d <image_name> - Run with Port Mapping:
docker run -p <host_port>:<container_port> <image_name> - Stop a Container:
docker stop <container_id> - Restart a Stopped Container:
docker start <container_id> - Remove a Container:
docker rm <container_id>
📜 Image Management
- List Images:
docker images - Pull an Image:
docker pull <image_name> - Build from Dockerfile:
docker build -t <image_name> . - Tag an Image:
docker tag <image_id> <new_image_name>:<tag> - Remove an Image:
docker rmi <image_id>
🔄 Managing Containers
- View Logs:
docker logs <container_id> - Access Container Shell:
docker exec -it <container_id> /bin/bash - Copy Files to Host:
docker cp <container_id>:<path_inside_container> <host_path>
🏗 Docker Networks
- List Networks:
docker network ls - Create Network:
docker network create <network_name> - Connect Container to Network:
docker network connect <network_name> <container_id>
🐳 Docker Compose
- Start Services in Detached Mode:
docker-compose up -d - Stop Services:
docker-compose down - Build & Start Containers:
docker-compose up --build
📊 Inspecting & Monitoring
- Inspect Container:
docker inspect <container_id> - Display Resource Usage:
docker stats
🛠 Volumes
- List Volumes:
docker volume ls - Create Volume:
docker volume create <volume_name> - 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
Post a Comment