Tech & DevOps HubEspace Tech & DevOps

Explorez le monde du Dev, du Cloud et des outils DevOps à travers nos articles et discussions Explore the world of development, the cloud and DevOps tools
 FR      EN
Docker
Général
Check Docker disk usage
docker system df

Displays disk usage for images, containers, and volumes.
View logs with timestamps
docker logs -f --timestamps my-container

Shows container logs with timestamp formatting.
Container
Copy file from container
docker cp my-container:/etc/nginx/nginx.conf .

Copies a file from a container to the host system.
Execute inside a container
docker exec -it my-container sh

Opens a shell in a running container.
Or, if a bash shell is installed in the container, use: docker exec -it my-container bash
Run a temporary container
docker run --rm -it alpine sh

Runs a temporary container and removes it after exit.
Inspect container IP
docker inspect my-container

Retrieves and displays the internal IP address assigned to the container named ‘my-container’ within its Docker networks.
A modern and shorter method (if the container uses the default network) docker inspect -f “{{.NetworkSettings.IPAddress}}” my-container
List containers
docker ps -a

Lists all containers, running or stopped.
Mount a volume
docker run -v /data:/app/data alpine

Mounts a volume inside a running or new container.
Remove stopped containers
docker container prune

Deletes all stopped containers.
View container stats
docker stats

Shows live resource statistics for running containers.
Image
Build an image
docker build -t myapp:1.0 .

Builds a Docker image from a Dockerfile.
List images
docker images

Lists all Docker images present locally.
Clean unused resources
docker system prune -a

Cleans unused containers, images, volumes and cache.
Push an image
docker push registry.example.com/myapp:1.0

Pushes a Docker image to a registry.
Remove all images
docker rmi $(docker images -q) -f

WARNING: This command forcibly deletes all locally stored images.
Use docker image prune -a for a safer alternative.