Docker Commands: A Comprehensive List
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
Process Management
Volumes & Ports
- List volumes
- Create a volume
- Delete a volume
- Show volume metadata
- Delete all volumes not attached to a container
- Mount a local directory to your container
- Copy file or folder from a docker container to host machine
- Copy file or folder from local machine onto a container
- Map a local port to a docker instance
- List the ports a docker container is running on
Docker Compose
Images/Repository
Troubleshooting
- Show the logs of a container
- Follow/tail the logs of a container
- Show timestamps on docker logs
- Show details/metadata of a container
- Show a ‘top’ view of processes running on a container
- Show a ‘top’ view of all docker containers
- Show any files that have changed since startup
- Connect to an already running container
- Execute a command on a container
- Show docker system wide information
- Show docker disk space used
Docker Commands
Process Management
- Show all running docker containers1docker ps
- Show all docker containers1docker ps -a
- Run a container1docker run <image>:<tag>
- Run a container and connect to it1docker run -it <image>:<tag>
- Run a container in the background1docker run -d <image>:<tag>
- Stop a container1docker stop <container>
- Kill a container1docker kill <container>
- Show all running docker containers
Volumes & Ports
- List volumes1docker volume ls
- Create a volume1docker volume create <volume>
- Delete a volume1docker volume rm <volume>
- Show volume metadata1docker volume inspect <volume>
- Delete all volumes not attached to a container1docker volume prune
- Mount a local directory to your container1docker run -v <local_dir>:<container_dir> <image>
- Copy file or folder from a docker container to host machine1docker cp container>:<container_dir> <local_dir>
- Copy file or folder from local machine onto a container1docker cp <local_dir> <container>:<container_dir>
- Map a local port to a docker instance1docker run -d -p 127.0.0.1:<local_port>:<docker_port> <image>
- List the ports a docker container is running on1docker port <container>
- List volumes
Docker Compose
- Start your docker-compose defined resources in detached mode1docker-compose up -d -f <docker_compose_yaml>
- Stop all docker-compose resources1docker-compose stop
- Destroy all docker-compose resources1docker-compose down
- Show docker-compose processes1docker-compose ps
- Show docker-compose logs1docker-compose logs
- Show docker-compose resource consumption1docker-compose top
- Start your docker-compose defined resources in detached mode
Images/Repository
- List available local images1docker images
- Search for docker images1docker search <image>
- Pull a docker image1docker pull <image>
- Build an image with a dockerfile1docker build -t <image>:<tag> <run_directory> -f <dockerfile>
- Login to a remote repository1docker login <repository>
- Push an image to your remote repository1docker push <image>:<tag>
- Remove a local docker image1docker rmi <image>:<tag>
- Show metadata for an image1docker inspect <image>
- Remove all unused docker images1docker image prune
- List available local images
Troubleshooting
- Show the logs of a container1docker logs <container>
- Follow/tail the logs of a container1docker logs -f <container>
- Show timestamps on docker logs1docker logs -t <container>
- Show details/metadata of a container1docker inspect <container>
- Show a ‘top’ view of processes running on a container1docker top <container>
- Show a ‘top’ view of all docker containers1docker stats
- Show any files that have changed since startup1docker diff <container>
- Connect to an already running container1docker attach <container>
- Execute a command on a container1docker exec -it <container_id> /bin/bash
- Show docker system wide information1docker system info
- Show docker disk space used1docker system df
- Show the logs of a container
Understanding these commands will help you streamline your workflow, improve productivity, and make the most out of Docker’s containerization platform.