Docker

Docker commands

Loads of useful Docker commands to help you get started with Docker and manage your containers and images effectively.

Build image

You can build a docker image if you have a Dockerfile in the current directory. The image will be tagged as image:x.x.x and you can change it to whatever you want.

bash
docker build -t image:x.x.x .

Monitor stats

You can monitor the stats of a container using the following command:

bash
docker stats --no-stream

Get container's IP

You can get the IP of a container using the following command:

bash
docker inspect -f "{{.NetworkSettings.IPAddress}}" <container_name>

Remove unused images

You can remove all unused images using the following command:

bash
docker image prune -a

Clean build cache

You can clean the build cache because this stacks up quite a lot.

bash
docker builder prune -af

Kill all containers

You can kill all running containers using the following command:

bash
docker kill $(docker ps -q)

Delete all stopped containers

You can delete all stopped containers using the following command:

bash
docker rm $(docker ps -a -q)

Delete all images

You can delete all images using the following command:

bash
docker rmi $(docker images -q)

Delete all volumes

You can delete all volumes using the following command:

bash
docker volume rm $(docker volume ls -q)

Docker prune

This command speaks for itself.

bash
docker system prune -af