docker
Docker commands categorized for managing containers, images, networks, volumes and more.
Containers
Commands for managing running and stopped containers.
List all containers
Shows running containers by default, use `-a` to show all.
docker ps -a
Start a container
Starts a stopped container.
docker start <container_id>
Stop a container
Stops a running container.
docker stop <container_id>
Remove a container
Deletes a stopped container.
docker rm <container_id>
Images
Commands for managing Docker images.
List images
Displays a list of all locally stored images.
docker images
Remove an image
Deletes a Docker image from local storage.
docker rmi <image_id>
Pull an image
Downloads an image from a Docker registry.
docker pull <image_name>
Build an image
Builds a Docker image from a Dockerfile.
docker build -t <image_name> .
Volumes
Commands for managing Docker volumes.
List volumes
Shows all Docker volumes.
docker volume ls
Create a volume
Creates a new Docker volume.
docker volume create <volume_name>
Remove a volume
Deletes a Docker volume.
docker volume rm <volume_name>
Networks
Commands for managing Docker networks.
List networks
Displays all Docker networks.
docker network ls
Create a network
Creates a custom Docker network.
docker network create <network_name>
Connect a container to a network
Attaches a container to a specified network.
docker network connect <network_name> <container_id>
Disconnect a container from a network
Detaches a container from a network.
docker network disconnect <network_name> <container_id>
Docker Compose
Commands for managing multi-container applications using Docker Compose.
Start services
Starts all services defined in the `docker-compose.yml` file.
docker compose up -d
Stop services
Stops all running services.
docker compose down
Restart services
Restarts all running services.
docker compose restart
View service logs
Displays logs for all services.
docker compose logs -f
List running services
Shows all active services.
docker compose ps
Execute a command in a service container
Runs a command inside a running service.
docker compose exec <service_name> <command>
Build images
Builds images for services defined in the `docker-compose.yml` file.
docker compose build
Docker Build
Commands for building and managing Docker images.
Build an image from a Dockerfile
Creates a Docker image from a Dockerfile in the current directory.
docker build -t <image_name> .
Build an image with no cache
Forces a fresh build without using cached layers.
docker build --no-cache -t <image_name> .
Build an image with a specific Dockerfile
Specifies a custom Dockerfile for the build.
docker build -f <Dockerfile> -t <image_name> .
Build and push an image in one command
Builds and directly pushes the image to a registry.
docker buildx build --push --tag <registry>/<image_name>:<tag> .
Show build cache usage
Displays information about the build cache.
docker system df
System Cleanup
Commands for cleaning up unused Docker resources.
Remove all stopped containers
Deletes all stopped containers.
docker container prune
Remove all unused images
Deletes all dangling images.
docker image prune
Remove all unused volumes
Deletes all unused volumes.
docker volume prune
Remove all unused networks
Deletes all unused networks.
docker network prune
Miscellaneous
Various useful Docker commands that don't fit into other categories.
Run a container interactively
Starts a container and opens an interactive shell session.
docker run -it <image_name> /bin/bash
Execute a command as a specific user
Runs a command inside a running container.
docker exec -u 1000:1000 -it <container_id> /bin/bash
Copy files from container to host
Copies files from a running container to the local filesystem.
docker cp <container_id>:/path/to/file /destination/path
Get detailed container information
Displays low-level information about a container.
docker inspect <container_id>
Get container resource usage stats
Displays real-time CPU, memory, and I/O statistics for containers.
docker stats
Get container logs in real-time
Shows logs from a running container.
docker logs -f <container_id>