Docker Commands

Commands for containers, images, volumes and Compose projects. Every item below is clearly marked as a shortcut, command, or syntax reference.

Most Useful Docker Commands

DockerCommand

Run a Container

Type this command
docker run

Creates a container from an image and starts it. Add -d to run it in the background.

Learn More
DockerCommand

List Running Containers

Type this command
docker ps

Shows the containers that are currently up, with their ID, name, image, status and ports.

Learn More
DockerCommand

Open a Shell in a Running Container

Type this command
docker exec -it CONTAINER bash

Runs a command inside a container that is already up, such as a bash prompt.

Learn More
DockerCommand

Build an Image

Type this command
docker build -t NAME .

Builds an image from the Dockerfile in the current folder.

Learn More
DockerCommand

Start a Compose Project

Type this command
docker compose up

Builds, creates and starts every service in your compose file.

Learn More
DockerCommand

List All Containers

Type this command
docker ps -a

Shows running containers plus the ones that have stopped.

Learn More
DockerCommand

Stop a Container

Type this command
docker stop

Sends a shutdown request and stops a running container.

Learn More
DockerCommand

Read Container Logs

Type this command
docker logs CONTAINER

Prints the output a container has written. Add -f to keep watching new lines.

Learn More

More Docker Commands

Frequently Asked Questions

What are the most useful Docker commands?

Common Docker commands include Run a Container (docker run), List Running Containers (docker ps), Open a Shell in a Running Container (docker exec -it CONTAINER bash), Build an Image (docker build -t NAME .), Start a Compose Project (docker compose up).

Where do I type Docker commands?

Type each command in the terminal or command-line interface used by Docker.

What should I check before running a Docker command?

Read its reference page and the linked documentation for prerequisites and placeholders. Check the current directory and target before running commands that change or delete data.