Top 20 Essential Docker Commands You Should Know in 2023

Docker is a powerful containerization platform that enables developers to package applications and their dependencies into lightweight, portable containers. Understanding Docker commands is essential for efficient container management, from creating and running containers to troubleshooting and maintaining them in development and production environments.

What is Docker?

Docker is a free and open-source platform that facilitates container development, administration, and operation in remote or local environments. It provides OS-level virtualization through containers, allowing applications to run consistently across different environments. As a Platform as a Service (PaaS) tool, Docker simplifies application deployment by bundling apps with their dependencies into portable units.

Below are the 20 most essential Docker commands every developer should master

Container Lifecycle Commands

1. docker run

Creates and starts a new container from an image. This is the most fundamental Docker command.

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
docker run -d --name my-app nginx

2. docker stop

Gracefully stops a running container by sending a SIGTERM signal.

docker stop [CONTAINER_ID or NAME]
docker stop my-app

3. docker kill

Forcefully terminates a container by sending a SIGKILL signal. Use only when docker stop fails.

docker kill [CONTAINER_NAME]
docker kill my-app

4. docker restart

Stops and then starts a container again.

docker restart [CONTAINER_NAME]
docker restart my-app

5. docker pause / docker unpause

Suspends all processes in a container without stopping it.

docker pause [CONTAINER_NAME]
docker unpause [CONTAINER_NAME]

Container Information Commands

6. docker ps

Lists running containers. Use -a flag to show all containers (running and stopped).

docker ps
docker ps -a

7. docker logs

Displays logs from a container, essential for debugging applications.

docker logs [CONTAINER_ID or NAME]
docker logs -f my-app

8. docker inspect

Returns detailed information about containers or images in JSON format.

docker inspect [IMAGE_NAME or CONTAINER_NAME]
docker inspect nginx

Image Management Commands

9. docker pull

Downloads an image from Docker registry (Docker Hub by default).

docker pull [IMAGE_NAME]
docker pull ubuntu:20.04

10. docker push

Uploads a local image to a Docker registry.

docker push [IMAGE_NAME]
docker push myusername/my-app:latest

11. docker rmi

Removes one or more images from the local system.

docker rmi [IMAGE_ID]
docker rmi nginx ubuntu

12. docker search

Searches Docker Hub for images matching the specified term.

docker search [TERM]
docker search nginx

13. docker history

Shows the history of an image, including all layers and commands used to build it.

docker history [IMAGE_NAME]
docker history nginx

Container Interaction Commands

14. docker exec

Executes commands inside a running container.

docker exec -it [CONTAINER_NAME] /bin/bash
docker exec my-app ls /app

15. docker cp

Copies files between a container and the host filesystem.

docker cp [CONTAINER_NAME]:[SRC_PATH] [DEST_PATH]
docker cp my-app:/app/config.json ./backup/

16. docker rename

Changes the name of an existing container.

docker rename [OLD_NAME] [NEW_NAME]
docker rename old-container new-container

System and Registry Commands

17. docker info

Displays system-wide information about Docker installation.

docker info

18. docker login

Authenticates with a Docker registry using your credentials.

docker login
docker login registry.example.com

19. docker logout

Logs out from a Docker registry.

docker logout
docker logout registry.example.com

20. docker commit

Creates a new image from changes made to a container.

docker commit [CONTAINER_NAME] [NEW_IMAGE_NAME]
docker commit my-app my-app:v2

Command Usage Comparison

Command Category Primary Commands Use Case
Container Lifecycle run, stop, kill, restart Managing container states
Container Info ps, logs, inspect Monitoring and debugging
Image Management pull, push, rmi, search Working with Docker images
Container Interaction exec, cp, rename Accessing and modifying containers

Conclusion

These 20 essential Docker commands form the foundation for effective container management. Mastering these commands enables developers to build, deploy, and maintain containerized applications efficiently. Regular practice with these commands will significantly improve your Docker workflow and troubleshooting capabilities.

Updated on: 2026-03-17T09:01:38+05:30

320 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements