Docker
Section titled “Docker”Basics
Section titled “Basics”Check Docker Version
Section titled “Check Docker Version”docker --versiondocker versionShow System-wide Docker Information
Section titled “Show System-wide Docker Information”docker infoUninstall Old Versions
Section titled “Uninstall Old Versions”sudo apt remove docker docker-engine docker.io containerd runcInstall Docker on Linux (Debian/Ubuntu)
Section titled “Install Docker on Linux (Debian/Ubuntu)”sudo apt updatesudo apt install -y docker.ioStart Docker Service
Section titled “Start Docker Service”sudo systemctl start dockersudo systemctl enable dockerDocker Image Management
Section titled “Docker Image Management”docker search <image_name> # Search for images on Docker Hubdocker pull <image_name>:<tag> # Pull an image from a registrydocker images # List all locally downloaded imagesdocker tag <src>:<tag> <dest>:<tag> # Create a new tag (alias) for an imagedocker inspect <image_id_or_name> # Inspect metadata (JSON format)docker history <image_id_or_name> # View the history/layers of an imagedocker rmi <image_id_1> <image_id_2> # Remove one or more specific imagesdocker image prune # Remove all unused (dangling) imagesdocker image prune -a # Remove all images not used by any containerDocker Container Management
Section titled “Docker Container Management”docker run <image_name> # Create and run a container from an imagedocker run -it <image_name> /bin/bash # Run interactively with a terminaldocker run -d <image_name> # Run in detached (background) modedocker run --name <name> <image_name> # Run and assign a custom namedocker run --rm <image_name> # Run and automatically remove after exitdocker ps # List all currently running containersdocker ps -a # List all containers (running + stopped)docker start <id_or_name> # Start a stopped containerdocker stop <id_or_name> # Gracefully stop a running containerdocker restart <id_or_name> # Restart a containerdocker kill <id_or_name> # Forcefully kill a running containerdocker pause <id_or_name> # Pause all processes in a containerdocker unpause <id_or_name> # Resume a paused containerdocker rename <old> <new> # Rename an existing containerdocker rm <id_or_name> # Remove a stopped containerdocker rm -f <id_or_name> # Force remove a running containerdocker logs <id_or_name> # View container output logsdocker logs -f <id_or_name> # Stream/follow container logs in real-timedocker top <id_or_name> # Display running processes of a containerdocker inspect <id> | grep -i limits # View resource limits for a containerDocker Networking Management
Section titled “Docker Networking Management”docker network ls # List all available Docker networksdocker network create <network_name> # Create a new custom networkdocker network connect <net> <container> # Attach a running container to a networkdocker network disconnect <net> <container> # Detach a container from a networkdocker network inspect <network_name> # View detailed configuration and connected containersdocker network rm <network_name> # Remove one or more networksdocker network prune # Remove all unused networksDocker Volume Management
Section titled “Docker Volume Management”docker volume ls # List all available Docker volumesdocker volume create <volume_name> # Create a new named volumedocker run -v <vol>:<path> <image> # Map a volume to a container pathdocker run -v my_data:/data nginx:latest # Example: Map 'my_data' volume to '/data'docker volume rm <volume_name> # Remove a specific volume (must be unused)docker volume inspect <volume_name> # View volume metadata (mount point, driver)docker volume ls -f dangling=true # List volumes not attached to any containerdocker volume prune # Remove all unused (dangling) volumesDocker Build Management
Section titled “Docker Build Management”docker build -t <name>:<tag> . # Build an image from Dockerfile in current dirdocker build -t <name>:<tag> <path> # Build an image from a specific directory pathdocker build -f <filename> -t <name> . # Build using a specific filename (not 'Dockerfile')docker build --no-cache -t <name> . # Rebuild image from scratch without using cachedocker build --pull -t <name> . # Always attempt to pull a newer version of the base imagedocker build --build-arg <key>=<val> . # Pass variables to the Dockerfile at build-timedocker build --target <stage> -t <name> . # Build a specific stage in a multi-stage Dockerfiledocker build --quiet -t <name> . # Suppress build output and print image ID onlydocker build --squash -t <name> . # Squash newly created layers into a single new layerDocker Compose Management
Section titled “Docker Compose Management”docker-compose up # Create and start containers defined in YAMLdocker-compose up -d # Run containers in the background (detached)docker-compose up --build # Rebuild images before starting containersdocker-compose down # Stop and remove containers, networks, and imagesdocker-compose down --volumes # Stop and remove containers AND named volumesdocker-compose start # Start existing containers for a servicedocker-compose stop # Stop running containers without removing themdocker-compose pause # Pause running containers of a servicedocker-compose unpause # Unpause containers of a servicedocker-compose ps # List containers related to the current YAML filedocker-compose logs # View output logs from all servicesdocker-compose logs -f # Stream/follow logs from all services in real-timedocker-compose build # Build or rebuild services defined in the filedocker-compose build --no-cache # Rebuild services from scratch without using cachedocker-compose pull # Pull images for services defined in the filedocker-compose exec <service> <command> # Execute a command in a running service containerdocker-compose run <service> <command> # Run a one-off command for a servicedocker-compose config # Validate and view the Compose file configurationdocker-compose restart # Restart all service containersDocker System Cleanup
Section titled “Docker System Cleanup”docker container prune # Remove all stopped containersdocker image prune # Remove all unused (dangling) imagesdocker image prune -a # Remove all images not used by any containerdocker volume prune # Remove all unused volumes (not used by any container)docker network prune # Remove all unused networksdocker system prune # Remove all stopped containers, unused networks, and dangling imagesdocker system prune -a # Remove all unused images, not just dangling onesdocker system prune --volumes # Remove everything above PLUS all unused volumesdocker system df # Show Docker disk usage and reclaimable spaceAdvanced & Debugging Operations
Section titled “Advanced & Debugging Operations”docker exec -it <id_or_name> /bin/bash # Open an interactive shell inside a running containerdocker save -o <path>.tar <image>:<tag> # Export an image to a tar archivedocker load -i <path>.tar # Load an image from a tar archivedocker export <id_or_name> > <path>.tar # Export container's filesystem as a tar archivedocker import <path>.tar <image_name> # Create an image from a container tarballdocker inspect <id_or_name> # Return low-level information on Docker objectsdocker stats # Display a live stream of container resource usage statisticsdocker info # Display system-wide information/daemon statusDocker Registry & Distribution
Section titled “Docker Registry & Distribution”docker login # Log in to a Docker registry (defaults to Docker Hub)docker logout # Log out from a Docker registrydocker tag <id> <repo>/<name>:<tag> # Tag an image into a specific repositorydocker push <repo>/<name>:<tag> # Upload an image to a registrydocker pull <repo>/<name>:<tag> # Download an image from a specific registryDocker Swarm (Orchestration)
Section titled “Docker Swarm (Orchestration)”docker swarm init # Initialize a swarm (current node becomes manager)docker swarm join --token <tkn> <ip>:<port> # Join a node to the swarm as a workerdocker node ls # List nodes in the swarm (Manager only)docker stack deploy -c <file>.yml <name> # Deploy or update a stack from a Compose filedocker stack services <name> # List services running in the stackdocker stack rm <name> # Remove a stack and its servicesResource Constraints & Security
Section titled “Resource Constraints & Security”docker run --cpus="1.0" <image> # Limit container to 1.0 CPU coresdocker run -m 512m <image> # Limit container memory to 512MBdocker run --user "$(id -u):$(id -g)" <img| # Run container with specific UID/GIDdockerd-rootless-setuptool.sh install # Set up Docker to run without root privilegesKubernetes Integration (Tools)
Section titled “Kubernetes Integration (Tools)”docker info | grep -i kubernetes # Check if K8s is enabled in Docker Desktopkompose convert # Convert Docker Compose file to K8s manifestskompose up # Deploy Compose-defined services directly to K8s