ํ™”. 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! ๐Ÿ‘‡๐Ÿ˜Š

๋‹ต๊ธ€ ๋‚จ๊ธฐ๊ธฐ

์ด๋ฉ”์ผ ์ฃผ์†Œ๋Š” ๊ณต๊ฐœ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜ ํ•„๋“œ๋Š” *๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค