Skip to content

30 Docker Commands to Manage Containers

It’s been five years since I started using Docker in production. Over time, I’ve become familiar with its API for packaging and distributing my applications. Daily use—whether writing a Dockerfile, running containers, or debugging issues—makes you internalize its API, which is actually quite intuitive.

I’ll group the commands according to their use:

  1. docker —version

    Terminal window
    docker --version

    Shows the installed version of Docker on your system.

  2. docker info

    Terminal window
    docker info

    Provides detailed information about your Docker installation, including containers, images, and system configuration.

  3. docker login

    Terminal window
    docker login

    Allows you to authenticate with a Docker registry (such as Docker Hub) so you can push or pull private images.

  1. docker pull

    Terminal window
    docker pull <image_name>

    Downloads an image from a Docker registry to your local machine.

  2. docker images

    Terminal window
    docker images
    *************************************************************************************
    REPOSITORY TAG IMAGE ID CREATED SIZE
    ruizdev7/portfolio-frontend 1.0.0 bc5e7370f8a7 11 days ago 54.2MB
    ruizdev7/portfolio-backend 1.0.0 777aed368f07 11 days ago 246MB
    moby/buildkit buildx-stable-1 72a94020693f 2 months ago 216MB
    mysql 8.0 c6f7ec307380 3 months ago 772MB
    excalidraw/excalidraw latest 4c54ecfa158f 3 months ago 92.9MB
    fireflyiii/core latest f5e8a551d54b 4 months ago 733MB
    jc21/nginx-proxy-manager latest 9f5e0949eb63 4 months ago 1.09GB
    alpine latest aded1e1a5b37 5 months ago 7.83MB
    nginx latest 53a18edff809 5 months ago 192MB

    Lists all Docker images stored locally.

  3. docker rmi

    Terminal window
    docker rmi <image_id>

    Removes a Docker image from your local machine.

  4. docker build

    Terminal window
    docker build -t <image_name> .

    Builds a Docker image from a Dockerfile.

  1. docker run

    Terminal window
    docker run -d --name <container_name> <image_name>

    Creates and runs a new container from an image. Useful flags include:

    • -d --detach: runs the container in the background and prints the container ID
    • --name <container_name> <image_name>: creates a container from the selected image and assigns it a name.
  2. docker ps

    Terminal window
    docker ps
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    a0b311e915b8 jc21/nginx-proxy-manager:latest "/init" 5 days ago Up 4 days 0.0.0.0:80-81->80-81/tcp, 0.0.0.0:443->443/tcp proxy-manager
    bc6eaa1e2d87 excalidraw/excalidraw:latest "/docker-entrypoint.…" 5 days ago Up 4 days (healthy) 0.0.0.0:5001->80/tcp excalidraw
    668a3af577fa ruizdev7-portfolio-backend "flask run --host=0.…" 5 days ago Up 4 days 0.0.0.0:8000->6000/tcp backend
    e789e5c966f3 ruizdev7-portfolio-frontend "docker-entrypoint.s…" 5 days ago Up 4 days 0.0.0.0:5173->3000/tcp frontend

    Shows the containers currently running.

  3. docker ps -a

    Terminal window
    docker ps -a

    Lists all containers, including those that are stopped.

  4. docker stop

    Terminal window
    docker stop <container_id>

    Stops a running container.

  5. docker start

    Terminal window
    docker start <container_id>

    Starts a stopped container.

  6. docker restart

    Terminal window
    docker restart <container_id>

    Restarts a container (stops and starts it again).

  7. docker rm

    Terminal window
    docker rm <container_id>

    Removes a container (it must be stopped first).

  8. docker exec

    Terminal window
    docker exec -it <container_id> /bin/bash

    Runs a command inside a running container (for example, opens a bash terminal).

  1. docker volume create

    Terminal window
    docker volume create <volume_name>

    Creates a new Docker volume for persistent data storage.

  2. docker volume ls

    Terminal window
    docker volume ls

    Lists all existing volumes.

  3. docker volume inspect

    Terminal window
    docker volume inspect <volume_name>

    Shows detailed information about a specific volume.

  4. docker volume rm

    Terminal window
    docker volume rm <volume_name>

    Removes a volume.

  1. docker network create

    Terminal window
    docker network create <network_name>

    Creates a new Docker network.

  2. docker network ls

    Terminal window
    docker network ls

    Lists all Docker networks.

  3. docker network inspect

    Terminal window
    docker network inspect <network_name>

    Shows detailed information about a specific network.

  4. docker network connect

    Terminal window
    docker network connect <network_name> <container_name>

    Connects a container to an existing network.

  5. docker network disconnect

    Terminal window
    docker network disconnect <network_name> <container_name>

    Disconnects a container from a network.

  1. docker-compose up

    Terminal window
    docker-compose up

    Builds, creates, starts, and attaches the services defined in a docker-compose.yml file.

  2. docker-compose down

    Terminal window
    docker-compose down

    Stops and removes the containers, networks, images, and volumes defined by docker-compose.yml.

  3. docker-compose ps

    Terminal window
    docker-compose ps

    Lists the containers managed by Docker Compose.

  4. docker-compose build

    Terminal window
    docker-compose build

    Builds or rebuilds the services defined in docker-compose.yml.

  5. docker-compose logs

    Terminal window
    docker-compose logs

    Shows the logs of the containers managed by Docker Compose.

  6. docker-compose exec

    Terminal window
    docker-compose exec <service_name> <command>

    Runs a command in a container managed by Docker Compose.

These commands cover the basics of Docker and should help you get started with managing Docker containers, images, volumes, networks, and using Docker Compose for multi-container applications.