Docker commands from basic to advanced

Basic Docker Commands:

// Show Docker version information
docker version

// Display system-wide information
docker info

// Show help information for Docker commands
docker --help

Image Management:

// List local images
docker images

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

// Remove a local image
docker rmi <image>

// Build an image from a Dockerfile
docker build -t <tag> <path>

Container Lifecycle:

// List running containers
docker ps

// List all containers (running and stopped)
docker ps -a

// Create and start a container from an image
docker run <image>

// Execute a command in a running container
docker exec -it <container> <command>

// Start a stopped container
docker start <container>

// Stop a running container
docker stop <container>

// Restart a container
docker restart <container>

// Remove a stopped container
docker rm <container>

// View logs of a container
docker logs <container> 

Networking:

// List Docker networks
docker network ls

// Create a Docker network
docker network create <network>

// Attach a container to a specific network
docker run --network=<network>

Volume Management:

// List Docker volumes
docker volume ls

// Create a Docker volume
docker volume create <volume>

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

Docker Compose:

// Start services defined in a docker-compose.yml
docker-compose up

// Stop and remove services defined in a docker-compose.yml
docker-compose down

Docker Registry:

// Log in to a Docker registry
docker login

// Push an image to a Docker registry
docker push <image>

// Pull an image from a Docker registry
docker pull <registry>/<image>

Swarm (Docker’s Orchestration Tool):

// Initialize a swarm
docker swarm init

// List services in a swarm
docker service ls

// List nodes in a swarm
docker node ls

Docker System Cleanup:

// Show Docker disk usage
docker system df

// Remove unused data (containers, networks, volumes, etc.)
docker system prune