Top 20 Essential Docker Commands You Should Know in 2023

Docker kill terminates a container if it takes too long to stop, while docker stop allows it to shut down normally. Software developers and engineers for building, testing, and managing environments for software development and testing widely use Docker. Containers allow for OS-level virtualization. Also, engineers may be able to communicate more rapidly without wasting time installing unnecessary programme requirements. This means programmers can make "portable containers" that can be taken anywhere, greatly simplifying remote teamwork. The container bundles the app and its prerequisites into one portable unit. As physical hardware is removed, computing resources can be used more effectively.

What is Docker?

Docker is a free and open-source platform that facilitates container development, administration, and operation in remote or local environments. Docker's many commands can seem overwhelming to someone new to the platform. Because a container contains the application and its dependencies, Docker also allows applications to be moved easily. It's a PaaS (platform as a service) tool that enables virtualization for containerized programme deployment.

Docker has a vast quantity of documentation, and it can be difficult to go through it all. The majority of the time, however, you'll utilize one of the more popular instructions.

So, now we will examine 20 of the most important commands in Docker −

Docker Run −

The Docker is used to construct and start containers. This command displays both active and terminated containers. Executing this command will first check for an existing container image, and if none is identified, it will generate and execute a new one.


Docker Restart

Once a container has been stopped, you can restart it with this command. Here is an example −

Docker restart [ container name ]    

Docker Stop

When you use this command, any currently operating containers will immediately terminate. Invoking this command terminates an active container, and this command terminates the container independently of the Docker kill command.

Docker stop [container ID or name] 

Docker Pause and Unpause

With this command, you can stop everything running inside a container. The example is like this −

Docker pause [container name]

With the resume command, containers can be resumed from a paused state −

Docker unpause [container name]

Docker Rename

Renaming a container is as simple as issuing this command.

docker rename [current_name] [new_name]

Docker Search

This command allows you to browse the primary Docker hub for available images. A pop-up window, including the image's title, description, and other details, will appear.

docker search 

Docker kill

By using this command, you can signal to a container that it should be destroyed. When executed, this command will immediately terminate the container's execution, and it triggers the SIGKILL signal without formally requesting termination.

Avoid using this command unless absolutely necessary; use docker stop first.

docker kill [container name]

Docker Pull

The docker repository can be queried for images with this command.

Docker pull [container name]

Docker cp

Use this command to move data between a container and its host machine. The random.conf file in the test-container will be copied and pasted into the test directory, which should be in the same location, by running this command.

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

Docker Login

To use this command, you must provide your Docker hub credentials. Simply enter this command into your terminal to access the Docker hub.

docker login

Docker Commit

When working on a system with a localized environment, you can use this command to generate or save a container image.

Docker commit  [container name]

Docker ps

This command can display a complete list of all currently-running containers. In order to interact with a container that is already operating, use this command.

docker ps—-all

Docker Exec

This allows you to issue new commands to a running container. It creates a new container named ubuntu 1 and starts a Bash session.

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

Docker rmi

If you want to use this function, you'll need to know the image ID before you can use the command. To free up space on the host node, you can use this command to add an image.

docker rmi [add image ID]

Docker Logout

This command will predictably sign you out of the Docker registry.

docker logout

Docker Logs

You can use this command to inspect the logs for any Docker container. This is useful when going back over mistakes and fixing them.

docker logs [container ID or name]

Docker Info

It's a basic command that will display data about the host machine on which Docker is installed.

docker info

Docker History

This will let you see all of the commits and changes made to the image, beginning with the most recent one. This command will provide a complete audit trail of any image in your Docker repository.

docker history [ container name ]

Docker Inspect

You can use this command to get some of the most fundamental information about your images and containers, such as their checksum, layers, and IP address.

docker inspect [ image Name ]

Docker Push

To publish a Docker image to a repository or the Docker hub, use this command.

docker push [image ID]


Thanks to Docker technology, containers can be used for the development, distribution, and execution of software. Sharing a container ensures that all users will receive the same instance when they communicate with it and will be able to use it in the same way. A container is a piece of software that encapsulates a programme and all its prerequisites to run in any setting. The number of networks and storage devices attached to a single container is unlimited.

Updated on: 27-Apr-2023


Kickstart Your Career

Get certified by completing the course

Get Started