Important Docker Commands You Should Know to Become a Docker Expert

Docker Commands

Docker is a powerful platform that lets users build, run, and manage applications inside containers. To handle tasks like building images or managing containers, networks, and volumes, we use Docker commands. Knowing these commands helps us work with containerized applications efficiently.

In this guide, we’ll explore the important Docker commands every user should learn. Each command includes syntax, examples, and practical use cases to help you understand how they work in real projects.

CommandDescriptionBasic Syntax
docker psList running containersdocker ps [OPTIONS]
docker runCreate and start a new container from an image.docker run [OPTIONS] IMAGE
docker stopStop a running container.docker stop CONTAINER
docker startResume a previously stopped container.docker start CONTAINER
docker restartRestart a container to apply changes.docker restart CONTAINER
docker execRun a command inside a running container.docker exec [OPTIONS] CONTAINER COMMAND
docker logsView logs of a container.docker logs [OPTIONS] CONTAINER
docker buildCreate a custom Docker image from a Dockerfile.docker build [OPTIONS] PATH
docker imagesList local Docker images.docker images
docker rmiRemove a Docker image.docker rmi IMAGE
docker pullDownload an image from a registry.docker pull IMAGE
docker pushPush an image to a registry.docker push IMAGE
docker statsMonitor real-time resource usage.docker stats [CONTAINER]
docker system pruneRemove unused containers, images, networks, and optionally volumes.docker system prune [OPTIONS]
docker-compose upStart multi-container services defined in a compose file.docker-compose up [OPTIONS]
docker-compose downStop and remove multi-container services.docker-compose down

Now let’s look at some simple examples to understand how these commands work in real situations.

List Docker Containers

The docker ps command shows all running containers. It works like a task manager for Docker and displays the container ID, name, status, and port mappings.

docker ps
List Docker Containers

You can also use the docker ps command with the -a option to view both running and stopped containers.

docker ps -a
List All Containers

Create and Start a New Container

The docker run command is used to start a new container from an image, which is usually the first step when launching an application.

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

You can adjust how the container starts by using different options. For example, the -d option runs the container in the background so your terminal stays free, and the -p option maps ports between your system and the container. Here is a simple example.

docker run -d -p 8080:80 nginx
Run New Container

This command starts an NGINX container in the background and makes it accessible on port 8080 of your machine. Open your browser and go to http://localhost:8080 or whichever port you mapped. If everything is working, you should see the default NGINX welcome page.

Nginx Welcome Page

Show Logs of a Container

The docker logs command lets you view the output generated by a container, whether it’s running or already stopped. It’s especially useful when you want to check what’s happening inside your application, look for errors, or understand why something isn’t working as expected. For example, you can use the following command to view the logs of a specific container, such as openwebui.

docker logs openwebui
Show Container Logs

Download an Image from a Registry

The docker pull command is used to download a Docker image from a public or private registry, such as Docker Hub. We run it when the required image isn’t already on our system. It helps us quickly get ready-made images without building them from scratch. We can also pull specific versions using tags, which ensures we’re working with the exact image version we need.

For example, you can run the following command to fetch the latest Ubuntu image.

docker pull ubuntu:latest
Download Docker Image

Inspect a Container or Image

The docker inspect command gives you detailed technical information about a container or image, such as network settings, mounted volumes, environment variables, and configuration details. For example, we use this command to inspect the OpenWebUI container.

docker inspect openwebui

This command is useful for debugging configuration issues or checking how a container is structured internally.

Inspect Container Image

Monitor Resource Usage

The docker stats command lets you track real-time network, CPU, memory, and disk usage for running containers.

docker stats
Monitor Resource Usage

You can also monitor a single container.

docker stats openwebui

It works like a live performance dashboard for Docker.

Monitor Specific Container

Start Multi-Container Applications

If your project uses multiple services like a backend API, frontend app, and database, you can manage all of them with Docker Compose. For example, you can use the following command to start everything defined in your Docker file.

docker compose up -d

Here, the -d flag runs services in the background. This command makes it easier to handle complex applications with just one command.

Docker Compose To Pull Image

Clean Up Unused Docker Resources

Docker collects unused data over time, such as old images, stopped containers, dangling volumes, and unused networks. You can clean them up with the following command.

docker system prune

Type y to clean the stopped containers, unused networks, dangling images, and unused build cache.

Clean Unused Resources

If you want to remove everything, including unused volumes and all unused images (not just dangling ones), you can use the following command.

docker system prune -a --volumes
Clean Everything

This keeps your system clean and prevents storage issues.

View All Available Docker Commands

If you ever forget a Docker command or want to explore more options, you can access the help page with this command.

docker --help
See All Available Docker Commands

Similarly, you can access the help page of a specific Docker command by specifying the command name. For example, the following command returns available flags, subcommands, and detailed descriptions for the docker ps command.

docker ps --help
Access Help Page Of Specific Command

This sums up the most important Docker commands developers use every day. You can also try other Docker tools like Docker Compose, Docker Desktop, or Docker Hub to manage and run your applications in even more useful ways.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Anees Asghar Avatar

Read next

The Roman aqueduct at Segovia, built around the first century AD without mortar, still carried water into the 1970s, its 167 granite arches held together by nothing but the precise weight distribution of stones cut to fit each other within fractions of a millimeter.
In 1843, Ada Lovelace described a brass-and-punched-card engine that could act on symbols as well as numbers, even composing music if harmony could be reduced to rules, inside seven translator’s notes three times longer than the paper itself
ARPANET sent its first message on 29 October 1969 from a lab at UCLA to a machine at Stanford, and the message was supposed to read ‘LOGIN’ — but the system crashed after the L and the O, meaning the first word ever transmitted over the network that became the internet was, by accident, ‘LO’.
In 1995, Microsoft shipped a cartoon-house interface called Bob, led by Melinda French, who married Bill Gates while it was in development — it demanded twice the memory of a typical home PC, sold roughly 30,000 copies, and was dead within a year, leaving behind the font Comic Sans and the animated assistant that became Clippy.
Apple’s original 1984 Macintosh keyboard had no arrow keys, no function keys, and no numeric pad because Steve Jobs wanted users to reach for the mouse first. Then Apple quietly sold the missing keys as an accessory.
In 1965, Mary Allen Wilkes wrote LAP6 for the LINC computer from her parents’ Baltimore home, testing an interactive operating system on a 250-pound machine in the living room and becoming the first known person to use a personal computer at home, twelve years before the Apple II reached buyers
In 1969, László Bélády and two IBM colleagues published a paging-machine anomaly showing FIFO could make four memory frames suffer ten page faults after three frames suffered nine, leaving generations of operating-systems students staring at the moment more memory became the wrong answer
In 1964, IBM risked its entire corporate empire on the System/360, a chaotic gamble to make all of its future machines compatible with the same software — and the architecture proved so robust that modern enterprise mainframes today are still running sections of binary code written more than sixty years ago