ν™”. 8μ›” 12th, 2025

D: Docker has revolutionized the way we develop, ship, and run applications. Whether you’re a beginner or a seasoned developer, mastering Docker commands is essential. This guide covers everything from basic to advanced Docker commands with practical examples. Let’s dive in!


1. Getting Started with Docker Basics

πŸ”Ή docker --version

Check your Docker installation and version.

docker --version
# Output: Docker version 20.10.17, build 100c701

πŸ”Ή docker run – Run a Container

The most fundamental command. Pulls an image (if not locally available) and starts a container.

docker run hello-world  # Runs the official "hello-world" image

πŸ”Ή docker ps – List Running Containers

docker ps          # Shows active containers
docker ps -a       # Shows all containers (including stopped ones)

πŸ”Ή docker stop & docker start – Manage Containers

docker stop 
<container_id>   # Gracefully stops a container
docker start 
<container_id>  # Restarts a stopped container

2. Working with Docker Images

πŸ”Ή docker images – List Downloaded Images

docker images  # Lists all locally stored images

πŸ”Ή docker pull – Download an Image

docker pull nginx:latest  # Downloads the latest Nginx image

πŸ”Ή docker rmi – Remove an Image

docker rmi nginx  # Deletes the Nginx image (if no containers are using it)

πŸ”Ή docker build – Create an Image from a Dockerfile

docker build -t my-custom-image .  # Builds an image from Dockerfile in current dir

3. Advanced Container Management

πŸ”Ή docker exec – Run Commands Inside a Running Container

docker exec -it 
<container_id> bash  # Opens an interactive shell

πŸ”Ή docker logs – View Container Logs

docker logs 
<container_id>  # Shows logs (useful for debugging)

πŸ”Ή docker inspect – Get Detailed Container Info

docker inspect 
<container_id>  # Returns JSON metadata (IP, volumes, etc.)

4. Networking & Port Forwarding

πŸ”Ή docker network ls – List Networks

docker network ls  # Shows available Docker networks

πŸ”Ή docker run -p – Port Mapping

docker run -p 8080:80 nginx  # Maps host port 8080 → container port 80

πŸ”Ή docker network create – Create Custom Networks

docker network create my-network  # Creates a new bridge network

5. Volume Management (Persistent Data)

πŸ”Ή docker volume ls – List Volumes

docker volume ls  # Shows all Docker volumes

πŸ”Ή docker run -v – Mount a Volume

docker run -v /host/path:/container/path nginx  # Binds a host directory

πŸ”Ή docker volume create – Create a Named Volume

docker volume create my-data  # Creates a persistent volume

6. Docker Compose for Multi-Container Apps

πŸ”Ή docker-compose up – Start Services

docker-compose up -d  # Runs containers in detached mode

πŸ”Ή docker-compose down – Stop Services

docker-compose down  # Stops and removes containers, networks

πŸ”Ή docker-compose logs – View Logs

docker-compose logs -f  # Follow logs in real-time

7. Cleaning Up Docker

πŸ”Ή docker system prune – Free Up Space

docker system prune -a  # Removes unused images, networks, and containers

πŸ”Ή docker rm – Remove Stopped Containers

docker rm $(docker ps -aq)  # Deletes all stopped containers

πŸš€ Pro Tips for Docker Power Users

  • Use --restart unless-stopped to auto-restart containers.
  • Combine docker stats for real-time resource monitoring.
  • Leverage .dockerignore to speed up builds (like .gitignore).

Final Thoughts

Mastering Docker commands unlocks the full potential of containerization. From simple docker run to complex docker-compose setups, these commands form the backbone of modern DevOps.

πŸ’‘ Now it’s your turn! Try these commands in a sandbox environment and experiment. Happy Dockerizing! 🐳


πŸ”— Further Learning:

Got questions? Drop them in the comments! πŸ‘‡πŸ˜Š

λ‹΅κΈ€ 남기기

이메일 μ£Όμ†ŒλŠ” κ³΅κ°œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. ν•„μˆ˜ ν•„λ“œλŠ” *둜 ν‘œμ‹œλ©λ‹ˆλ‹€