20 Essential Docker Commands You Should Know

Sure! Here’s the translated text in American English:

Docker is a widely used tool by developers and software engineers for creating, testing, and managing development environments that facilitate the running of their applications in containers. This container platform is fundamental in modern software development, allowing applications to be easily portable and capable of running in any environment without the need for modifications.

Below is a list of 20 essential Docker commands that every developer and system administrator should know to manage their containers efficiently.

What is Docker?

Docker is an open-source container platform that enables developers to create, manage, and run applications in containers. These containers include everything needed to run an application, such as the code, libraries, and configurations, making it easy to deploy applications across different environments without worrying about operating system dependencies.

Docker is fundamental for deploying scalable and efficient systems both in the cloud and on local servers. Additionally, it provides a cost-effective solution as it is more resource-efficient than traditional virtual machines.

20 Essential Docker Commands and What They Do

Here are the 20 most commonly used commands in Docker, along with their descriptions and usage examples.

1. docker run

This command is used to create and run containers. If the container does not exist yet, Docker will look for the image and download it. If the image does not exist locally, a new one will be created.

Example:

docker run --name nginx-container -p 8080:80 -d nginx

This will run a container with Nginx, mapping port 80 of the container to port 8080 of the host.

2. docker search

This command allows you to search for images on Docker Hub.

Example:

docker search nginx

This displays available Nginx images, including descriptions and popularity.

3. docker stop

This command stops a running container in a controlled manner.

Example:

docker stop nginx-container

4. docker rename

This command renames a container.

Example:

docker rename nginx-container new-nginx-container

5. docker restart

This command restarts a running container.

Example:

docker restart nginx-container

6. docker pause / unpause

This command pauses or resumes the execution of all processes within a container.

Example:

docker pause nginx-container
docker unpause nginx-container

7. docker kill

This command sends a forced termination signal to a container.

Example:

docker kill nginx-container

Generally used in emergencies when docker stop is not sufficient.

8. docker pull

This command downloads an image from a repository, such as Docker Hub.

Example:

docker pull ubuntu:latest

This downloads the latest version of the Ubuntu image.

9. docker ps

This command shows the running containers.

Example:

docker ps

To see all containers, including stopped ones, use docker ps -a.

10. docker login

This command logs in to Docker Hub or another Docker registry.

Example:

docker login

This will prompt you for your Docker Hub credentials.

11. docker commit

This command creates a new image from changes made to a container.

Example:

docker commit nginx-container my-nginx-image

12. docker exec

This command allows you to run commands inside a running container.

Example:

docker exec -it nginx-container bash

This will open an interactive terminal inside the nginx-container.

13. docker rmi

This command removes an image from the local system.

Example:

docker rmi nginx-image

14. docker cp

This command copies files or directories between a container and the host.

Example:

docker cp nginx-container:/path/to/file /host/path

15. docker logs

This command shows the logs of a running container.

Example:

docker logs nginx-container

16. docker info

This command displays information about the Docker system and host.

Example:

docker info

17. docker logout

This command logs out of Docker Hub or any registry you are using.

Example:

docker logout

18. docker inspect

This command shows detailed information about a container or image.

Example:

docker inspect nginx-container

19. docker history

This command shows the history of layers of a Docker image.

Example:

docker history nginx-image

20. docker push

This command uploads a local image to a Docker repository.

Example:

docker push my-nginx-image

This command uploads the image my-nginx-image to Docker Hub or the specified registry.

Summary: Docker Commands for Professionals

The commands mentioned above are some of the most commonly used in Docker, and mastering their use is essential to make the most of this powerful platform. While there are many other commands and variations you can use based on the specific needs of your project, these 20 commands will help you manage containers effectively in most cases.

What commands do you use most frequently? Every development environment is different, so it’s important to learn and experiment with these commands to see which are most useful in your workflow. Let us know in the comments how you use Docker and what your most frequently used command is!

Scroll to Top