Table of Contents

Docker Basics

// Check Docker version.
docker -V

// Display system-wide information about Docker.
docker info

// Download an image from Docker Hub.
docker pull <image_name>

// List local Docker images. 
docker images

// List running containers. 
docker ps

// List all containers (including stopped one).
docker ps -a

// Create and start a new container from an image. 
docker run <options> <image_name>

Container Lifecycle

// Start a stopped container. 
docker start <container_name/id>

// Stop a running container gracefully. 
docker stop <container_name/id>

// Forcefully stop a running container. 
docker kill <container_name/id>

// Restart a container. 
docker restart <container_name/id>

// Remove a stopped container. 
docker rm <container_name/id>

Images

// Build a Docker image from a Dockerfile 
docker build -t <image_name> <path_to_Dockerfile>

// Remove an image.
docker rmi <image_name>

// Remove all unused images. 
docker image prune

Docker Compose

// Start services defined in a Docker Compose file
docker-compose up

// Stop and remove services defined in a Docker Compose file.
docker-compose down

// List services in a Compose file and their status. 
docker-compose ps

// View logs for a specific service.
docker-compose logs <service_name>

// Run a command in a running service container.
docker-compose exec <service_name> <command>

Volumes

// Create a named volume.
docker volume create <volume_name>

// Mount a volume to a container.
docker run -v <volume_name>:<container_path>

// List volumes.
docker volume ls

// Remove a volume.
docker volume rm <volume_name>

Docker Registry and Hub

// Log in to a Docker registry.
docker login

// Push an image to a registry.
docker push <image_name>

// Pull an image from a registry.
docker pull <image_name>

Networks

// Create a user-defined network.
docker network create <network_name>

// List networks.
docker network ls

// Connect a container to a network.
docker network connect <network_name> <container_name/id>

// Disconnect a container from a network.
docker network disconnect <network_name> <container_name/id>

Logs and Debugging

// View container logs.
docker logs <container_name/id>

// Start an interactive shell in a running container.
docker exec -it <container_name/id> /bin/bash

// Display real-time container resource usage.
docker stats <container_name/id>

Cleanup

// Remove all stopped containers, unused networks, and images.
docker system prune

// Remove all stopped containers.
docker container prune

// Remove all unused images.
docker image prune

// Remove all unused volumes.
docker volume prune
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to BugFix.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.