Docker is commonly used by software developers and engineers to develop, test, and control the conditions in which they test their software. It allows software developers to create portable containers, making it easy to collaborate with others remotely. 

If you’re new to Docker, learning all of the commands may seem a bit daunting at first. The sheer amount of documentation available for Docker can be overwhelming to review. However, there are some commands which are more commonly used than others. 

What is Docker?

Docker is a free, open-source platform that lets developers create, manage, and run containers in the cloud or on servers. It’s considered a PaaS (platform-as-a-service) product that lets developers use virtualization to run software in containers. 

Docker makes it easy for developers to use system resources more efficiently, as containerized apps generally use less memory when compared with virtual machines. Docker also makes applications portable, since a container includes everything the application requires to work. 

You just need Docker runtime on a host to easily execute a Docker container. Now that you know the basics, let’s look at 20 essential Docker commands. 

20 Essential Docker Commands and What They Do

Here are 20 essential Docker commands, including their intended functions. 

1. Docker run

The Docker run command is used to create and start containers. When you run this command, it’s going to first look for a container image. 

If one is not found, it will create a new one and run it.


Here’s an example of running a Nginx container from Docker’s repository.

docker run —-name nginx-root -p 8080:80 -d nginx

The -d means that the container will run in the background detached, while you can also customize the name flag and map the container port to the host port.

You can use this command to search for different images from the main Docker hub. It will show you information about the image, including its name, description, and other specifications. 

Here’s an example:

docker search nginx

3. Docker stop

This command is used to stop containers that you’re running. Unlike the docker kill command, this one stops the container in its own time. Here’s how to use it:

docker stop [container name or ID]

4. Docker rename

This one’s fairly self-explanatory. If you want to rename a container, you can use this command. Here’s the syntax:

docker rename [current_name] [new_name]

5. Docker restart

If you’ve stopped a container, you can restart it using this command. The syntax is as follows:

docker restart [container name]

6. Docker pause or unpause

This command lets you pause or suspend all processes running within a container. Here’s the syntax that you use:

docker pause [container name]

You can also unpause containers using the unpause command:

docker unpause [container name]

7. Docker kill

This command can be used to send the “KILL” signal to a container. It sends a SIGKILL signal without sending a request for termination. 

Generally, this command is in typical emergency situations, which is why it’s generally a wise idea to use the docker stop command before trying this. 

docker kill [container name]

8. Docker pull

The docker pull command can be used to pull an image from the Docker Hub. Here’s the basic syntax:

docker pull [container name]

You can also use tags to identify images, including the -all-tags- command to pull all images from a repository. 

9. Docker ps

If you want to list all containers that are running in the background, you can use this command. Here’s the syntax:

docker ps—-all

10. Docker login

If you want to log into the Docker hub, you can use this command. When you use this command, you’ll have to enter your Docker hub credentials. 

docker login

11. Docker commit

You can use this command to save an image of a container or create one on a localized system. 

docker commit [container name]

12. Docker exec

You can use this to execute new commands in a container that is already running.

docker run --name ubuntu_1 --rm -i -t ubuntu bash

This will create a new container entitled ubuntu_1 and launch a Bash session.

13. Docker rmi

If you want to remove an image from the host node and free up some space you can use this command. You will have to add the image ID to run this command. 

docker rmi [add image ID]

14. Docker cp

This command is used to copy files and directories from the container to the host and vice versa. 

docker cp test-container:/1/2/random.conf ./test

This command is going to copy the random.conf file from the test-container and then paste it into the test directory, which would ideally be present in the same directory. 

15. Docker logs

If you want to check the logs for all Docker containers, you can use this command. This is great when you want to review errors and then resolve problems. Here’s the syntax for it:

docker logs [container name or ID]

16. Docker info

This is a fairly simple command that will show you information about the localhost, or the host on which Docker is running. The syntax is fairly simple:

docker info

17. Docker logout

As you can imagine, this command will log you out of the Docker hub. The syntax is straightforward:

docker logout

18. Docker inspect

If you want some basic information about the images and the containers, such as the checksum, layers, or the container’s IP address, you can use this command. 

The syntax for this is as follows:

docker inspect [image name]

19. Docker history

If you want to go through the history of any image on your Docker system, you can use this command to get all the information you require. 

This can help you identify any changes made to the image, as well as any commits, starting from the most recent one. Here’s the syntax:

docker history [container name]

20. Docker push

This command is used to upload a Docker image to a particular repository or the Docker hub. Here’s the syntax for it:

docker push [image ID]

After Action Report – Which Commands Do You Use Most Frequently?

There are hundreds of different Docker commands and thousands of variations in total. Which Docker commands do you use most frequently? Let us know & join the conversation in the comments (or by Tweeting @RunCloud_io) what your preferred server file management process currently looks like! 💬