docker
CLI commands to build, run, manage containers, images, networks, volumes, compose, security, and swarm.
Containers
Commands for managing running and stopped containers.
List All Containers
Shows running containers by default or all containers.
docker ps -aStart Stopped Container
Starts a stopped container instance.
docker start <container_id>docker start web_appStop Running Container
Gracefully stops a running container instance.
docker stop <container_id>docker stop web_appRemove Stopped Container
Deletes a stopped container from disk.
docker rm <container_id>docker rm web_appRun Interactive Container
Starts a container and opens a shell session.
docker run -it <image_name> <command>docker run -it ubuntu bashExecute Container Command
Runs a command inside a running container.
docker exec -it <container_id> <command>docker exec -it web_app bashCopy Container Files
Copies files between a container and host filesystem.
docker cp <container_id>:<path> <destination>docker cp web_app:/app/logs.txt ./logs.txtInspect Container Metadata
Displays low-level metadata about a container.
docker inspect <container_id>docker inspect web_appView Resource Statistics
Displays real-time CPU, memory, and I/O statistics.
docker statsView Container Logs
Shows logs from a running container.
docker logs -f <container_id>docker logs -f web_appImages and Building
Commands for managing and building container images.
List Local Images
Displays a list of all locally stored images.
docker imagesPull Remote Image
Downloads an image from a container registry.
docker pull <image_name>docker pull nginx:latestBuild Image From Dockerfile
Creates a Docker image from a local Dockerfile.
docker build -t <image_name> .docker build -t my-app .Build Without Cache
Forces a fresh build without using cached layers.
docker build --no-cache -t <image_name> .docker build --no-cache -t my-app .Build Custom Dockerfile
Specifies a custom Dockerfile for the build process.
docker build -f <dockerfile> -t <image_name> .docker build -f Dockerfile.prod -t my-app .Remove Local Image
Deletes a Docker image from local storage.
docker rmi <image_id>docker rmi my-appBuild And Push Image
Builds and directly pushes the image to a registry.
docker buildx build --push --tag <registry>/<image>:<tag> .docker buildx build --push --tag myregistry.com/my-app:latest .Volumes and Persistent Storage
Commands for managing volumes and persistent storage.
List Docker Volumes
Shows all provisioned Docker volumes.
docker volume lsCreate Persistent Volume
Creates a new persistent data volume.
docker volume create <volume_name>docker volume create pg_dataRemove Docker Volume
Deletes an unused Docker data volume.
docker volume rm <volume_name>docker volume rm pg_dataRun With Bind Mount
Mounts a host directory into a container.
docker run -v <host_path>:<container_path> <image_name>docker run -v /host/data:/app/data my-appNetworks and Custom Bridges
Commands for managing networks and custom bridge configurations.
List Docker Networks
Displays all active Docker networks.
docker network lsCreate Custom Bridge Network
Creates a custom user-defined bridge network.
docker network create --driver bridge <network_name>docker network create --driver bridge app_netConnect Container To Network
Attaches a container to a specified network.
docker network connect <network_name> <container_id>docker network connect app_net web_appDisconnect Container Network
Detaches a container from a network.
docker network disconnect <network_name> <container_id>docker network disconnect app_net web_appDocker Compose
Commands for managing multi-container applications using Compose.
Start Compose Services
Starts all services defined in configuration files.
docker compose up -dStop Compose Services
Stops and removes active container services.
docker compose downRestart Compose Services
Restarts all running multi-container services.
docker compose restartView Compose Logs
Displays real-time logs for all services.
docker compose logs -fList Compose Services
Shows all active services and container statuses.
docker compose psExecute Service Command
Runs a command inside a running service container.
docker compose exec <service_name> <command>docker compose exec app bashBuild Compose Services
Builds images for services defined in configuration.
docker compose buildDocker Security Best Practices
Commands and configurations for enforcing container security hardening.
Run As Non Root
Executes container processes using a non-root user ID.
docker run --user <uid>:<gid> <image_name>docker run --user 1000:1000 my-appScan Image Vulnerabilities
Analyzes container images for known security vulnerabilities.
docker scout quickview <image_name>docker scout quickview nginx:latestCheck Rootless Status
Verifies if the Docker daemon runs in rootless mode.
docker info --format '{{.SecurityOptions}}'Docker Secrets
Commands for securely managing sensitive configuration data.
Create Docker Secret
Creates a new encrypted secret object in Swarm.
echo "<secret_value>" | docker secret create <secret_name> -echo "my_password" | docker secret create db_password -List Docker Secrets
Displays all stored secret objects.
docker secret lsInspect Docker Secret
Displays low-level metadata of a secret object.
docker secret inspect <secret_name>docker secret inspect db_passwordRemove Docker Secret
Deletes an existing secret object.
docker secret rm <secret_name>docker secret rm db_passwordDocker Swarm Basics
Commands for orchestrating multi-node container clusters.
Initialize Docker Swarm
Initializes the current node as a Swarm manager.
docker swarm initJoin Swarm Cluster
Connects a worker or manager node to a cluster.
docker swarm join --token <token> <manager_ip>:<port>docker swarm join --token SWMTKN-1-xx 192.168.1.10:2377List Swarm Nodes
Displays all nodes participating in the Swarm cluster.
docker node lsCreate Swarm Service
Deploys a replicated service across the Swarm.
docker service create --name <service_name> --replicas <num> <image_name>docker service create --name web --replicas 3 nginxList Swarm Services
Displays all active services running in the Swarm.
docker service lsSystem Cleanup
Commands for cleaning up unused system resources.
Remove Stopped Containers
Deletes all stopped containers to reclaim space.
docker container pruneRemove Unused Images
Deletes unreferenced dangling and unused images.
docker image pruneRemove Unused Volumes
Deletes orphaned volumes not used by containers.
docker volume pruneRemove Unused Networks
Cleans up unused custom networks.
docker network pruneView System Disk Usage
Displays disk space utilization by Docker objects.
docker system df