금. 7월 25th, 2025

Hello! 🐳 Welcome to Docker, the name synonymous with container technology. In modern software development, Docker has become an essential tool for deploying and managing applications easily and efficiently. However, if you’re new to Docker, many of its commands can be a bit intimidating.

This article is designed for those who are just getting started with Docker or who need a refresher on the basics. We’ve handpicked the 30 most important and frequently used commands that cover the core features of Docker, and we’ll explain in detail what they do, how to use them, and even provide real-world examples. We hope this guide will help you become more familiar with Docker and make your development workflow more efficient!

—.

🚀 Before you begin: A quick review of Docker basics

Before we dive into exploring commands, let’s take a moment to review two key concepts in Docker.

  • Image: 📦 A read-only template that contains everything an application needs to run (code, runtime, system tools, libraries, etc.). It can be likened to a “class” or “blueprint”.
  • Container: 🐳 An executable instance of the image. You can think of it as the ‘process’ by which the application actually works in an independent environment based on the image. It can be likened to an ‘object created from a class’ or an ‘actual product created from a blueprint’.

Now that you’re ready, let’s dive into the world of Docker commands.

—.

Ⅰ. Check Docker System & Info (System & Info) ⚙️

These commands check basic information about the Docker environment.

  1. docker version

    • Description: Shows the version of the currently installed Docker client and server (Daemon).
    • Implementation: docker version
    • Example:
      docker version
      Client: Docker Engine - Community
       Version: 24.0.5
       ...
      Server: Docker Engine - Community
       Engine:
        Version: 24.0.5
        ...
  2. docker info

    • Description: Prints detailed information about the docker system as a whole. You can get a lot of useful information about containers, images, storage drivers, network settings, and more.
    • Usage: docker info
    • Example:
      docker info
      Client:
       Context: default
       ...
      Server:
       Containers: 3
        Running: 1
        Paused: 0
        Stopped: 2
       Images: 15
       Storage Driver: overlay2
       ...

—]

Ⅱ. Image Management (Image Management) 📦

Commands used to download, create, view, and delete Docker images.

  1. docker pull [:tag]

    • Description: Download an image from a container registry, such as Docker Hub. If :tag is not specified, it defaults to downloading the latest tag.
    • Implementation: docker pull ubuntu:22.04
    • Example:
      docker pull ubuntu:22.04 # Download Ubuntu 22.04 image
      docker pull nginx # Download Nginx latest image
  2. docker images (or docker image ls)

    • Description: Retrieves a list of docker images stored on the local system. You can see the image ID, repository, tags, size, when it was created, etc.
    • Usage: docker images
    • Examples:
      docker images
      repository tag image id created size
      ubuntu 22.04 d70e332766xx 3 weeks ago 77.8MB
      nginx latest 53e41c4aa0xx 3 weeks ago 187MB
      my-app v1.0 a1b2c3d4e5xx 2 days ago 250MB
  3. docker build -t [:tag]

    • Description: Builds (creates) a new docker image according to the instructions defined in the Dockerfile. You can specify a name and tag for the image with the -t option.
    • Syntax: docker build -t my-web-app:1.0 . (uses the Dockerfile in the current directory)
    • Example:
      # Build the 'my-flask-app' image with the Dockerfile in the current directory, tagged with 'latest'
      docker build -t my-flask-app .
  4. docker tag [:new_tag]

    • Description: Gives an existing image a new name (tag). Typically used to indicate a specific version or to name a repository before pushing to Docker Hub.
    • Syntax: docker tag my-app:v1.0 myregistry/my-app:prod
    • Example:
      # Add the tag 'myuser/my-flask-app:production' to the image 'my-flask-app:latest'
      docker tag my-flask-app:latest myuser/my-flask-app:production
  5. docker rmi [:tag]

    • Description: Deletes a docker image from the local system. If containers are using that image, it will not be deleted. (You can force deletion with the -f option.)
    • Let’s run: docker rmi ubuntu:22.04
    • Example:
      docker rmi ubuntu:22.04 # Delete Ubuntu 22.04 image
      docker rmi -f 53e41c4aa0xx # Force delete by image ID
  6. docker push [:tag]

    • Description: Uploads a local image to a container registry, such as Docker Hub. To push, the image must be tagged in the following format: [registry_address]/[user_name]/[image_name]:[tag] (for Docker Hub, the registry address can be omitted)
    • Usage: docker push myuser/my-web-app:prod
    • Example: “`bash
      # push the image 'myuser/my-flask-app:production' to Docker Hub
      docker push myuser/my-flask-app:production
  7. docker search

    • Description: Searches for publicly available images on Docker Hub.
    • Implementation: docker search postgres
    • Examples:
      docker search postgres
      name description stars official automated
      postgres The PostgreSQL object-relational database...    11000 [OK]
      sameersbn/postgresql PostgreSQL container with support for backup... 200
      ...

—]

Ⅲ. Container Management 🐳 (Container Management) 🐳.

These are the core commands used to create, run, stop, view, delete, and control Docker containers.

  1. docker run [options] [:tag] [run_command]

    • Description: Create and run a new container from the specified image. This is one of the most important and used commands in Docker.
    • Key options:
      • -d (detached): Runs the container in the background and returns to the terminal.
      • -p :: Connect a port on the host to a port on the container (port forwarding).
      • -v :: Mount a volume between the host and the container to share or persist data.
      • --name: Give the container a recognizable name (if not specified, generates a random name)
      • --rm: Automatically delete the container when it is terminated.
      • -it: (Interactive, TTY) Go inside the container and allow terminal input. (Typically used with bash or sh)
      • --network: Connect the container to a specific network.
    • Usage: docker run -d -p 80:80 --name my-nginx nginx
    • Example:

      # Run an Nginx container in the background (-d), connect port 80 on the host to port 80 on the container (-p 80:80), and name the container my-nginx
      docker run -d -p 80:80 --name my-nginx nginx
      
      # Run the Ubuntu container, connect to the bash shell (-it), and auto-delete on exit (--rm)
      docker run -it --rm ubuntu bash
  2. docker ps (or docker container ls)

    • Description: Get a list of currently running containers. Use the -a option to show a list of all containers, even those that are not running (Stopped).
    • Setup: docker ps -a
    • Example:
      docker ps # List only running containers
      docker ps -a # List all containers (running, stopped, etc.)
      container id image command created status ports names
      a1b2c3d4e5f0 nginx "/docker-entrypoint...." 5 minutes ago Up 5 minutes 0.0.0.0:80->80/tcp my-nginx
  3. docker start

    • Description: Restarts a stopped container.
    • Implementation: docker start my-nginx
    • Example:
      docker start my-nginx # Start container 'my-nginx'
  4. docker stop

    • Description: Shut down a running container normally. Docker sends a SIGTERM signal to give the container’s main process time to shut down, and then SIGKILL if there is no response.
    • Let’s use it: docker stop my-nginx
    • Example:
      docker stop my-nginx # Stop container 'my-nginx'
  5. docker restart

    • Description: Stops and restarts a running container.
    • Implementation: docker restart my-nginx
    • Example:
      docker restart my-nginx # Restart container 'my-nginx'
  6. docker kill

    • Description: Force a running container to terminate immediately. Unlike stop, it sends a SIGKILL signal immediately without giving a grace period for termination.
    • Let’s use it: docker kill my-nginx
    • Example: “`bash
      docker kill my-nginx # Force termination of container 'my-nginx'
  7. docker rm

    • Description: Deletes a stopped container. Running containers will not be deleted; they can be forced with the -f (force) option.
    • How to: docker rm my-nginx
    • Example:
      docker rm my-nginx # Delete container 'my-nginx'
      docker rm -f running_container # Force delete running container
  8. docker exec -it

    • Description: Runs a command inside a running container. The -it option is often used to interactively access the shell inside the container.
    • Implementation: docker exec -it my-nginx bash
    • Example: `bash

      # Run the bash shell inside the 'my-nginx' container
      docker exec -it my-nginx bash
      
      # Run the ls /var/log/nginx command inside the 'my-nginx' container
      docker exec my-nginx ls /var/log/nginx
  9. docker logs [-f]

    • Description: Check the container’s standard output (stdout) and standard error (stderr) logs. The -f (follow) option will continue to print the logs in real time.
    • Implementation: docker logs -f my-nginx
    • Example: “`bash
      docker logs my-nginx # print all logs in the 'my-nginx' container
      docker logs -f my-nginx # Trace the logs of the 'my-nginx' container in real time
  10. docker cp

    • Description: Copies files between the host and the container.
    • Usage:
      • docker cp /host/path my-nginx:/container/path (host -> container)
      • docker cp my-nginx:/container/path /host/path (Container -> Host)
    • Example: * “`bash

      # Copy the index.html file on the host to the /usr/share/nginx/html/ path of the 'my-nginx' container
      docker cp ./index.html my-nginx:/usr/share/nginx/html/index.html
      
      # Copy the /var/log/nginx/access.log file from the 'my-nginx' container to the current directory on the host
      docker cp my-nginx:/var/log/nginx/access.log .
  11. **`docker inspect

    `** * **Description:** Outputs detailed information about a docker object (container, image, network, volume, etc.) in JSON format. Useful for debugging or writing automation scripts. * **Setup:** `docker inspect my-nginx` * **Example:** “`bash docker inspect my-nginx # Get the details of the container ‘my-nginx’ docker inspect nginx:latest # Get the details of the ‘nginx:latest’ image. “`
  12. docker top

    • Description: Get a list of processes running inside a running container. Similar to the ps command, but shows the processes inside the container.
    • Setup: docker top my-nginx
    • Example:
      docker top my-nginx
      uid pid ppid c time tty time cmd
      root 1 0 0 17:23 ? 00:00:00 nginx: master process nginx -g daemon off;
      nginx 6 1 0 17:23 ? 00:00:00 nginx: worker process
  13. docker stats

    • Description: Provides a real-time streaming view of resource usage, including CPU usage, memory usage, and network I/O for all running containers.
    • Implementation: docker stats
    • Examples:
      docker stats
      container id name cpu % mem us / limit mem % net i/o block i/o pids
      a1b2c3d4e5f0 my-nginx 0.00% 4.63MiB / 7.69GiB 0.06% 5.85kB / 3.42kB 0B / 0B 2

—.

Ⅳ. Network Management 🌐 (Network Management)

Commands to manage communication between Docker containers and external network connections.

  1. docker network ls

    • Description: Gets a list of Docker networks that exist on the local system. By default, bridge, host, and none networks exist.
    • Implementation: docker network ls
    • Examples:
      docker network ls
      network id name driver scope
      8a9b7c6d5e4f bridge bridge local
      d1e2f3g4h5i6 host host local
      j7k8l9m0n1o2 none null local
  2. docker network create

    • Description: Creates a user-defined bridged network; containers connected to the same network can communicate with each other by name.
    • Syntax: docker network create my-custom-network
    • Example:
      docker network create my-web-net # Create a network named 'my-web-net'
  3. docker network connect

    • Description: Connects a running container to a specific network.
    • Syntax: docker network connect my-web-net my-app-container
    • Example:
      # Connect 'my-app-container' to the 'my-web-net' network
      docker network connect my-web-net my-app-container
  4. docker network rm

    • Description: Deletes a user-defined network. If there are containers associated with it, it will not be deleted.
    • Syntax: docker network rm my-web-net
    • Example:
      docker network rm my-web-net # Delete network 'my-web-net'

—]

Ⅴ. Volume Management 💾 â-Ž

These are commands used to permanently store and manage data in a Container.

  1. docker volume ls

    • Description: Gets a list of docker volumes created on the local system.
    • Implementation: docker volume ls
    • Example:
      docker volume ls
      driver volume name
      local my-app-data
      local db-data
  2. docker volume create

    • Description: Creates a new named volume. The volume persists even if the container is deleted, ensuring persistence of data.
    • Syntax: docker volume create my-app-data
    • Example:
      docker volume create my-db-data # Create volume 'my-db-data'
  3. docker volume rm

    • Description: Deletes a docker volume. Be careful, as all data stored in the volume will be permanently deleted.
    • Syntax: docker volume rm my-app-data
    • Example:
      docker volume rm my-db-data # Delete volume 'my-db-data'

—]

Ⅵ. System Management & Cleanup (System Management & Cleanup) 🧹 😒

Commands to manage the overall health of your Docker environment and clean up unused resources.

  1. docker system prune
    • Description: Free up disk space by deleting unused Docker resources (containers, images, networks, volumes, etc.) in bulk.
    • Key options:
      • -a (all): Deletes all unused data, including stopped containers, unused images, networks, cache build images, etc. (very powerful, use with caution)
      • --volumes: Delete even unused volumes (by default, volumes are not deleted)
    • How to use: docker system prune -a --volumes
    • Example:
      docker system prune # Delete stopped containers, unused images, and networks
      docker system prune -a # Delete all stopped containers, unused images (including cache), and networks
      docker system prune --volumes # above + delete unused volumes

      Warning: This command can delete a lot of resources when executed, so use it carefully.

—]

🌟 Wrapping up: Your first step to Docker mastery!

We’ve just covered in detail the 30 core commands you’ll most likely encounter while using Docker. The power of Docker comes from the ability to combine and utilize these commands. It may seem complicated at first, but once you understand what each command does and practice consistently, you’ll soon find Docker to be an indispensable tool in your development environment.

We hope this guide serves as a great compass for your Docker learning journey. Keep experimenting with commands to get more comfortable, and explore higher-level concepts like Docker Compose and Docker Swarm. We wish you a more efficient and enjoyable development experience with Docker! 🚀 Happy Dockering! 🥳

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다