Essential Docker Commands Reference

System Information

Check Docker Version

docker version

Displays version information for both Docker client and server components.

View Docker System Details

docker info

Shows comprehensive system information including container counts, images, and configuration.

Access Command Help

docker --help

Displays usage information and lists all available Docker commands with thier options.

Image Management

List Local Images

docker images

Lists images stored locally on the system.

Option Description
-a Shows all images, including intermediate layers

Examples:

docker images -a

Search for Images

docker search image-name:tag

Searches the Docker registry for avialable images.

Example:

docker search httpd:latest

Pull Images

docker pull image-name:tag

Downloads an image from the registry to the local system.

Example:

docker pull redis:7.0

Remove Images

docker rmi image-identifier

Deletes specified images from the local repository.

Option Description
-f Forces removal of the image

Examples:

docker rmi -f abc123def456
docker rmi -f $(docker images -aq)

Create Custom Images

docker commit container-id repository:tag

Creates a new image from an existing container's changes.

Example:

docker commit a1b2c3d4 myapp:v1.0

Inspect Image Details

docker image inspect image-identifier

Returns detailed metadata about an image including layers, configuration, and environment variables.

Example:

docker image inspect nginx:latest

Build Images from Dockerfile

docker build -t repository:tag -f Dockerfile-path context-path

Constructs an image using a Dockerfile and build context.

Option Description
-t Sets the repository name and tag
-f Specifies the Dockerfile location

Example:

docker build -t webapp:2.0 -f ./Dockerfile.prod .

Container Operations

Create and Start Containers

docker run [options] image-name [command]

Creates and starts a new container from the specified image.

Option Description
--name Assigns a name to the container
-d Runs container in detached mode (background)
-p Maps host port to container port (host:container)
-it Interactive mode with terminal access

Examples:

docker run -d -p 8080:80 --name web nginx
docker run -it debian /bin/bash

List Containers

docker ps [options]

Displays running containers.

Option Description
-a Shows all containers (including stopped)
-n=x Lists the last x containers
-q Outputs only container IDs

Examples:

docker ps
docker ps -a
docker ps -aq

Execute Commands in Containers

docker exec [options] container-id command

Runs commands inside a running container.

Option Description
-it Interactive terminal session

Examples:

docker exec web-server ls /app
docker exec -it web-server /bin/sh

Container Lifecycle Mannagement

# Stop and exit interactive container
exit

# Start a stopped container
docker start container-id

# Restart a running container
docker restart container-id

# Stop a running container gracefully
docker stop container-id

# Forcefully terminate a container
docker kill container-id

Examples:

docker start a1b2c3d4
docker restart a1b2c3d4
docker stop a1b2c3d4
docker kill a1b2c3d4

View Container Logs

docker logs container-id

Retrieves output from the container's standard output and error streams.

Example:

docker logs web-server

Check Container Processes

docker top container-id

Displays running processes within the container.

Example:

docker top web-server

Inspect Container Configuration

docker inspect container-id

Returns low-level information about the container including network settings, mount points, and resource constraints.

Example:

docker inspect web-server

Delete Containers

docker rm container-id

Removes stopped containers from the system.

Example:

docker rm a1b2c3d4

Attach to Running Container

docker attach container-id

Connects to the standard input, output, and error streams of a running container.

Example:

docker attach web-server

Copy Files Between Host and Container

# Copy from container to host
docker cp container-id:/path/in/container /host/destination

# Copy from host to container
docker cp /host/source container-id:/path/in/container

Examples:

docker cp web-server:/var/logs/app.log ./logs/
docker cp ./config web-server:/etc/app/config

Tags: docker containerization devops command-line images

Posted on Sat, 09 May 2026 05:29:59 +0000 by hobeau