Basic Docker CLI Commands - snir1551/DevOps-Linux GitHub Wiki
Command | Description |
---|---|
docker pull <image> |
Download an image from Docker Hub |
docker build -t <name> . |
Build an image from a Dockerfile |
docker images |
List all local images |
docker rmi <image> |
Remove an image |
docker rmi $(docker images -q) |
Remove all images |
docker image prune |
Remove unused images |
docker tag <image> <new-name> |
Tag an image with a new name |
docker save -o <file>.tar <image> |
Save an image to a tar archive |
docker load -i <file>.tar |
Load an image from a tar archive |
Command | Description |
---|---|
docker run <image> |
Run a container |
docker run -it <image> bash |
Run interactively with a shell |
docker run -d <image> |
Run in detached mode |
docker run -p <host_port>:<container_port> <image> |
Map ports from container to host to allow external access |
docker ps |
List running containers |
docker ps -a |
List all containers (including stopped) |
docker stop <container> |
Stop a container |
docker start <container> |
Start a stopped container |
docker restart <container> |
Restart a container |
docker rm <container> |
Remove a container |
docker container prune |
Remove all stopped containers |
docker logs <container> |
Show container logs |
docker exec -it <container> bash |
Run a command inside a running container |
docker inspect <container> |
Show detailed info (JSON) |
docker top <container> |
Show running processes in container |
docker stats |
Show live resource usage stats |
docker stop $(docker ps -q) |
Stop all the containers |
Command | Description |
---|---|
docker volume create <name> |
Create a volume |
docker volume ls |
List all volumes |
docker volume inspect <name> |
Show detailed info about a volume |
docker volume rm <name> |
Remove a volume |
docker volume prune |
Remove all unused volumes |
Command | Description |
---|---|
docker network ls |
List all networks |
docker network create <name> |
Create a custom network |
docker network inspect <name> |
Show detailed info about a network |
docker network rm <name> |
Remove a network |
docker network connect <network> <container> |
Connect a container to a network |
docker network disconnect <network> <container> |
Disconnect a container from a network |
Command | Description |
---|---|
docker-compose up |
Start services defined in docker-compose.yml |
docker-compose up -d |
Start services in detached mode |
docker-compose down |
Stop and remove services, networks, volumes, and images created |
docker-compose ps |
List running services |
docker-compose build |
Build or rebuild services |
docker-compose logs |
View logs for all services |
docker-compose logs <service> |
View logs for a specific service |
docker-compose exec <service> bash |
Run a command inside a running service container |
Command | Description |
---|---|
docker system df |
Show disk usage by Docker |
docker system prune |
Remove all unused containers, networks, images (not just dangling) and optionally, volumes |
docker info |
Display system-wide information |
docker version |
Show the Docker version installed |
Command | Description |
---|---|
docker history <image> |
Show history of an image |
docker diff <container> |
Show changes in the container’s filesystem |
docker commit <container> <new-image> |
Create a new image from a container’s changes |
docker cp <container>:<path> <host_path> |
Copy file from container to host |
docker cp <host_path> <container>:<path> |
Copy file from host to container |
docker attach <container> |
Attach to a running container's STDIN/STDOUT |