How to manage Docker images

Pulling an image from the index

Before pulling an image locally, we need to know which images we have at our disposal. For that, let’s search the docker index, either from https://hub.docker.com or from the command line.

$ docker search debian --filter=is-official=true
NAME         STARS     OFFICIAL   AUTOMATED
debian       1655      [OK]
neurodebian  28        [OK]

Once we’ve identified an image, we can pull it. Usually we’d want the latest image, so we can pass the latest argument.

$ docker pull debian:latest
Pulling repository debian
8dbd9e392a96: Downloading 2.785 MB/58.34 MB (5%)
(snipped)

To confirm the image has been registered with the local Docker install, type:

$ docker images
REPOSITORY     TAG        IMAGE ID         CREATED         SIZE
debian         latest     031143c1c662     2 weeks ago     125.1 MB

Update all images

I can’t remember where I stole the below one-liner from but it’s very helpful, so I’ll share it with you regardless. Basically, this instructs Docker to pull every single image from the Docker Hub for new changes. Obviously, if you have created your own Docker images (and haven’t registered them on the Docker Hub), they will fail to be updated.

$ docker images | awk '(NR>1) && ($2!~/none/) {print $1":"$2}' | xargs -L1 docker pull

Remove all images

As time goes by, Docker images will take a lot of space on the disk. To remove all of them, run the below command:

$ docker rmi $(docker images -q)

If you want to bring this one step further and delete all containers (running or not) and images, just do the following:

Careful with this one, make sure you know what you’re doing!

$ docker rm -f $(docker ps -aq) && docker rmi $(docker images -q)

Tags
Cloud

Date
September 17, 2016