Clue Mediator

Docker Commands: A Comprehensive List

📅May 13, 2023

Docker is a powerful containerization platform that allows developers to package and deploy their applications in a portable way. However, mastering Docker requires familiarity with a wide range of commands. In this article, we will explore a comprehensive list of Docker commands that can help you manage containers, images, networks, and volumes.

Table of Contents

Docker Commands

  • Process Management

    • Show all running docker containers

      <code class="language-sh">docker ps
      

      ⬆ Back to Top

    • Show all docker containers

      <code class="language-sh">docker ps -a
      

      ⬆ Back to Top

    • Run a container

      <code class="language-sh">docker run <image>:<tag>
      

      ⬆ Back to Top

    • Run a container and connect to it

      <code class="language-sh">docker run -it <image>:<tag>
      

      ⬆ Back to Top

    • Run a container in the background

      <code class="language-sh">docker run -d <image>:<tag>
      

      ⬆ Back to Top

    • Stop a container

      <code class="language-sh">docker stop <container>
      

      ⬆ Back to Top

    • Kill a container

      <code class="language-sh">docker kill <container>
      

      ⬆ Back to Top

  • Volumes & Ports

    • List volumes

      <code class="language-sh">docker volume ls
      

      ⬆ Back to Top

    • Create a volume

      <code class="language-sh">docker volume create <volume>
      

      ⬆ Back to Top

    • Delete a volume

      <code class="language-sh">docker volume rm <volume>
      

      ⬆ Back to Top

    • Show volume metadata

      <code class="language-sh">docker volume inspect <volume>
      

      ⬆ Back to Top

    • Delete all volumes not attached to a container

      <code class="language-sh">docker volume prune
      

      ⬆ Back to Top

    • Mount a local directory to your container

      <code class="language-sh">docker run -v <local_dir>:<container_dir> <image>
      

      ⬆ Back to Top

    • Copy file or folder from a docker container to host machine

      <code class="language-sh">docker cp container>:<container_dir> <local_dir>
      

      ⬆ Back to Top

    • Copy file or folder from local machine onto a container

      <code class="language-sh">docker cp <local_dir> <container>:<container_dir>
      

      ⬆ Back to Top

    • Map a local port to a docker instance

      <code class="language-sh">docker run -d -p 127.0.0.1:<local_port>:<docker_port> <image>
      

      ⬆ Back to Top

    • List the ports a docker container is running on

      <code class="language-sh">docker port <container>
      

      ⬆ Back to Top

  • Docker Compose

    • Start your docker-compose defined resources in detached mode

      <code class="language-sh">docker-compose up -d -f <docker_compose_yaml>
      

      ⬆ Back to Top

    • Stop all docker-compose resources

      <code class="language-sh">docker-compose stop
      

      ⬆ Back to Top

    • Destroy all docker-compose resources

      <code class="language-sh">docker-compose down
      

      ⬆ Back to Top

    • Show docker-compose processes

      <code class="language-sh">docker-compose ps
      

      ⬆ Back to Top

    • Show docker-compose logs

      <code class="language-sh">docker-compose logs
      

      ⬆ Back to Top

    • Show docker-compose resource consumption

      <code class="language-sh">docker-compose top
      

      ⬆ Back to Top

  • Images/Repository

    • List available local images

      <code class="language-sh">docker images
      

      ⬆ Back to Top

    • Search for docker images

      <code class="language-sh">docker search <image>
      

      ⬆ Back to Top

    • Pull a docker image

      <code class="language-sh">docker pull <image>
      

      ⬆ Back to Top

    • Build an image with a dockerfile

      <code class="language-sh">docker build -t <image>:<tag> <run_directory> -f <dockerfile>
      

      ⬆ Back to Top

    • Login to a remote repository

      <code class="language-sh">docker login <repository>
      

      ⬆ Back to Top

    • Push an image to your remote repository

      <code class="language-sh">docker push <image>:<tag>
      

      ⬆ Back to Top

    • Remove a local docker image

      <code class="language-sh">docker rmi <image>:<tag>
      

      ⬆ Back to Top

    • Show metadata for an image

      <code class="language-sh">docker inspect <image>
      

      ⬆ Back to Top

    • Remove all unused docker images

      <code class="language-sh">docker image prune
      

      ⬆ Back to Top

  • Troubleshooting

    • Show the logs of a container

      <code class="language-sh">docker logs <container>
      

      ⬆ Back to Top

    • Follow/tail the logs of a container

      <code class="language-sh">docker logs -f <container>
      

      ⬆ Back to Top

    • Show timestamps on docker logs

      <code class="language-sh">docker logs -t <container>
      

      ⬆ Back to Top

    • Show details/metadata of a container

      <code class="language-sh">docker inspect <container>
      

      ⬆ Back to Top

    • Show a 'top' view of processes running on a container

      <code class="language-sh">docker top <container>
      

      ⬆ Back to Top

    • Show a 'top' view of all docker containers

      <code class="language-sh">docker stats
      

      ⬆ Back to Top

    • Show any files that have changed since startup

      <code class="language-sh">docker diff <container>
      

      ⬆ Back to Top

    • Connect to an already running container

      <code class="language-sh">docker attach <container>
      

      ⬆ Back to Top

    • Execute a command on a container

      <code class="language-sh">docker exec -it <container_id> /bin/bash
      

      ⬆ Back to Top

    • Show docker system wide information

      <code class="language-sh">docker system info
      

      ⬆ Back to Top

    • Show docker disk space used

      <code class="language-sh">docker system df
      

      ⬆ Back to Top

Understanding these commands will help you streamline your workflow, improve productivity, and make the most out of Docker's containerization platform.