This tutorial explains some of the most commonly used Docker commands.
Docker Terms
This section defines some of the most useful Docker terms.
Docker Image: A set of read-only files. These files are a part of an operating system that is required to run a Docker container.
Dockerfile: A simple text file that contains all the commands a user could call in the command line to assemble or build an image.
Docker Containers: Small and lightweight alternatives to Virtual Machines used to run the application in an isolated environment.
Docker Registry: A centralized place to store all Docker images that allows you to upload and download any images using the command-line.
Docker Volume: A mechanism or technique that stores the data generated by the Docker container.
Docker Network: Used to communicate between docker host and container.
Docker Information Commands
If you are responsible for managing Docker container and image, then you will need to know how to get important information about containers and images to manage them.
To print information about the Docker platform installed on your system, run the following command:
The command will provide detailed information of Docker, as in the following output:
Debug Mode: false
Server:
Containers: 10
Running: 2
Paused: 0
Stopped: 8
Images: 8
Server Version: 18.09.1
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: c4446665cb9c30056f4998ed953e6d4ff22c7c39
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 4.18.0-193.14.2.el8_2.x86_64
Operating System: CentOS Linux 8 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.94GiB
Name: centos8
ID: GWWI:E5JU:VW33:NKPG:NUSJ:Y5C3:JL55:FSKN:ONCD:GJXY:HTAZ:W7OD
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine
To list only running containers in your system, run the following command:
To list both running and stopped containers in your system, run the following command:
To print the logs of any running container, run the following command:
To print the object information about a container, run the following command:
To print all running processes in a container, run the following command:
To print the live resource usage of any container, run the following command:
To print the changes on files and directories in a filesystem, run the following command:
Docker Container Commands
To start a container, run the following command:
To stop a container, run the following command:
To pause a container, run the following command:
To restart a container, run the following command:
To unpause a paused container, run the following command:
To send a kill signal to a running container, run the following command:
To block until a running container stops, run the following command:
To connect to a running container, run the following command:
To rename an existing container, run the following command:
To create a container from an image without starting it, run the following command:
To start a new container from an image and remove the container upon exiting, run the following command:
To start a new container from an image and keep it running, run the following command:
To start a new container from an image and create an interactive bash shell in the container, run the following command:
To update the configuration of one or more containers, run the following command:
To remove a container if it is not running, run the following command:
Docker Image Commands
To pull an image from the Docker Hub registry, run the following command:
To create an image from the Dockerfile, run the following command:
To push an image to the Docker Hub registry, run the following command:
To create an image from a container, run the following command:
To save an image to the tar archive, run the following command:
To remove an image, run the following command:
To list all available images in your system, run the following command:
To display the history of an image, run the following command:
Docker Network Commands
This section shows you some network-related commands.
To list all the networks in your system, run the following command:
To print information about one or more networks, run the following command:
To connect a container to a network, run the following command:
To disconnect a container from a network, run the following command:
To remove one or more networks, run the following command:
Docker Volume Commands
This section shows you some volume-related commands in Docker.
To create a new Docker volume, run the following command:
To list all Docker volumes in your system, run the following command:
To print more information about a Docker volume, run the following command:
To remove a Docker volume from your system, run the following command:
Conclusion
In this guide, you learned about the most commonly used Docker-related commands. I hope this article will save you time when managing the Docker environment on your system.