$linuxjunkies
>

docker(1)

Manage Docker containers, images, networks, and volumes from the command line.

UbuntuDebianFedoraArch

Synopsis

docker [OPTIONS] COMMAND [ARG...]

Description

Docker is a containerization platform that allows you to package applications and their dependencies into isolated, lightweight containers. The docker command-line interface (CLI) provides tools to build, run, manage, and distribute containers and images.

Docker commands are organized into management commands (like docker container, docker image) and legacy commands (like docker run, docker build). Both forms work identically.

Common options

FlagWhat it does
-v, --versionShow Docker version information
-H, --hostDocker daemon socket or host to connect to (e.g., unix:///var/run/docker.sock or tcp://localhost:2375)
-D, --debugEnable debug mode for verbose output
--configLocation of client config files (default: ~/.docker)
-l, --log-levelSet logging level (debug, info, warn, error, fatal)
--tlsverifyUse TLS and verify the remote server certificate
--tlscacertPath to CA certificate file for TLS verification
-h, --helpShow help text for docker or a specific command

Examples

Run an nginx container in detached mode, mapping port 8080 on host to port 80 in container, naming it 'webserver'

docker run -d -p 8080:80 --name webserver nginx

List all containers (running and stopped) with their IDs, names, status, and ports

docker ps -a

Build a Docker image from a Dockerfile in the current directory, tagging it as 'myapp:1.0'

docker build -t myapp:1.0 .

Open an interactive bash shell inside a running container

docker exec -it container_id /bin/bash

Stream and follow the logs of a running container in real-time

docker logs --follow container_id

Download the Ubuntu 20.04 image from Docker Hub

docker pull ubuntu:20.04

List all local Docker images with their repository, tag, image ID, and size

docker images

Remove all stopped containers

docker rm $(docker ps -aq)

Related commands