Useful Docker Commands

Docker commands that can help you manage your Docker containers and images effectively.

Bart Tworek1 min readdocker

Show docker image layers

To show the layers of a Docker image, you can use the following command:

docker history --no-trunc --format '{{.ID}}\t{{.CreatedSince}}\t{{.CreatedBy}}\t{{.Size}}' <image-name>:<tag>

The --no-trunc flag stops Docker from truncating the layer IDs and commands, which is useful for seeing the full command that created each layer.

Show live resource usage for running containers

To monitor CPU, memory, network and disk I/O for all running containers in real time:

docker stats

Inspect a container or image

To see the full low-level configuration of a container or image (environment variables, mounts, network settings, and more) as JSON:

docker inspect <container-or-image-name>

Clean up unused resources

Docker keeps stopped containers, dangling images, unused networks and build cache around by default, which can use up a lot of disk space over time. To remove everything not currently in use by a running container:

docker system prune -a --volumes

Omit -a to only remove dangling images rather than all unused images, and omit --volumes to keep unused volumes (useful if you want to preserve data from stopped containers you might restart).