Docker Setup & System Information
Commands used to check installation, system status, and configuration.
Check Docker version
docker --version
Example:
docker --version
# Docker version 26.0.0
Display detailed Docker info
docker info
Shows containers, images, storage driver, CPU/memory, etc.
Docker help
docker help
Help for a specific command:
docker run --help
Docker Image Management
Images are templates used to create containers.
List local images
docker images
Example output:
REPOSITORY TAG IMAGE ID SIZE
nginx latest 605c77e6 142MB
Pull image from registry
docker pull nginx
Specific version:
docker pull python:3.11
Remove image
docker rmi nginx
Remove multiple:
docker rmi image_id1 image_id2
Build image from Dockerfile
docker build -t myapp .
Example:
docker build -t mynodeapp:v1 .
Tag an image
docker tag myapp:v1 username/myapp:v1
Push image to registry
docker push username/myapp:v1
Search images on Docker Hub
docker search redis
Docker Container Management
Containers are running instances of images.
Run container
docker run nginx
Run with interactive terminal:
docker run -it ubuntu bash
Run in detached mode:
docker run -d nginx
Run with port mapping:
docker run -p 8080:80 nginx
Run with name:
docker run --name mynginx nginx
Run with environment variable:
docker run -e MYSQL_ROOT_PASSWORD=secret mysql
List running containers
docker ps
List all containers:
docker ps -a
Stop container
docker stop container_id
Example:
docker stop mynginx
Start container
docker start container_id
Restart container
docker restart container_id
Remove container
docker rm container_id
Remove running container forcefully:
docker rm -f container_id
Container Inspection & Logs
View logs
docker logs container_id
Follow logs:
docker logs -f container_id
Inspect container details
docker inspect container_id
Shows JSON with configuration details.
Show running processes in container
docker top container_id
View container resource usage
docker stats
Example output:
CONTAINER CPU % MEM USAGE
nginx 0.12% 20MiB
Executing Commands in Containers
Run command in running container
docker exec container_id ls
Interactive shell:
docker exec -it container_id bash
Example:
docker exec -it mynginx sh
Docker Networking
List networks
docker network ls
Create network
docker network create mynetwork
Inspect network
docker network inspect mynetwork
Connect container to network
docker network connect mynetwork container_id
Remove network
docker network rm mynetwork
Docker Volume Management
Volumes store persistent data.
List volumes
docker volume ls
Create volume
docker volume create myvolume
Inspect volume
docker volume inspect myvolume
Remove volume
docker volume rm myvolume
Mount volume to container
docker run -v myvolume:/data nginx
Bind mount example:
docker run -v $(pwd):/app node
Docker Compose Commands
Used for multi-container applications with Docker Compose.
Start services
docker compose up
Detached mode:
docker compose up -d
Stop services
docker compose down
View running services
docker compose ps
View logs
docker compose logs
Build services
docker compose build
Docker Cleanup Commands
Remove stopped containers
docker container prune
Remove unused images
docker image prune
Remove unused volumes
docker volume prune
Remove everything unused
docker system prune
Aggressive cleanup:
docker system prune -a
Docker File Transfer
Copy files between container and host.
Copy from container:
docker cp container_id:/app/file.txt .
Copy to container:
docker cp file.txt container_id:/app
Advanced Docker Commands
Pause container
docker pause container_id
Unpause container
docker unpause container_id
Rename container
docker rename oldname newname
Update container resources
docker update --memory 500m container_id
Helpful Commands
List container IDs only:
docker ps -q
Remove all containers:
docker rm $(docker ps -aq)
Remove all images:
docker rmi $(docker images -q)