Às vezes, mesmo removendo o container e o volume, o Docker ainda pode usar cache de build para etapas específicas. Você pode limpar completamente o cache de build usando o seguinte comando:
docker builder prune --all --force
Este comando remove todos os build cache, forçando o Docker a reconstruir tudo desde o início na próxima vez que você construir as imagens.
By Dennis
2-minute read
Whether you’re just starting with Docker or already a professional, there are times when remembering the correct commands or the order of parameters can be challenging.
To make things easier, we’ve created this Docker commands cheat sheet to share with you.
Whenever you build your own container or need to timestamp the container you’re using, check out the free Timestamp Service for Code and Container.
docker ps
– List running containers.docker ps -a
– List all containers, including stopped ones.docker pull
– Download an image from Docker Hub registry.- The image link is displayed on the right on Docker Hub.
docker build
– Build your own container based on a Dockerfile.- Example:
docker build .
builds from the current directory. - Example:
docker build -t "myimage:latest" .
creates and tags an image.
- Example:
docker images
ordocker image ls
– Show all locally stored images.docker run
– Run a Docker container based on an image.- Example:
docker run myimage -it bash
. - If the image is not found locally, Docker pulls it from the registry.
- Example:
docker logs
– Display logs of a specified container.- Example:
docker logs -f mycontainer
continues showing updates.
- Example:
docker volume ls
– List volumes, commonly used to persist container data.docker network ls
– List all Docker networks.docker network connect
– Add a container to a network for communication by name instead of IP.docker rm
– Remove containers.- Example:
docker rm mycontainer
(ensure it’s not running).
- Example:
docker rmi
– Remove images.- Example:
docker rmi myimage
(ensure no container uses the image).
- Example:
docker stop
– Stop containers.- Example:
docker stop mycontainer
stops one. - Example:
docker stop $(docker ps -a -q)
stops all.
- Example:
docker start
– Start a stopped container with its last state.docker update
– Update container policies.- Example:
docker update --restart=no
helps with crash loops.
- Example:
docker cp
– Copy files between a container and the host.- Example:
docker cp <container_name_or_id>:/etc/file .
- Example:
- Kill all running containers:
docker kill $(docker ps -q)
- Delete all stopped containers:
docker rm $(docker ps -a -q)
- Delete all images:
docker rmi $(docker images -q)
- Stop a container in a crash loop:
docker update --restart=no && docker stop <container_name>
- Bash into a container:
docker exec -i -t <container_name> /bin/bash
- Use
/bin/sh
if Bash is unavailable.
- Use
- Bash as root in a container:
docker exec -i -t -u root <container_name> /bin/bash
- Get Docker containers with size:
docker ps -s
- Get disk utilization:
docker system df
- Remove unused, untagged images:
docker image prune
- Delete all unused images:
docker image prune -a
- Clean up images older than 24 hours:
docker image prune -a --filter "until=24h"
- Clean up stopped containers:
docker container prune
- Truncate container logs:
truncate -s 0 $(docker inspect --format='' <container_name_or_id>)
Let us know if there are any commands you think are essential!
Note: Many of these commands also work with Podman instead of Docker.