Managing local docker images
1. Managing local docker images
Until now, images have been made available in the exercises when you need them. In practice, images are either custom-made or downloaded from Docker Hub.2. Docker Hub
Docker Hub is a registry of community-made Docker images. In other words, it's a website from which we can download thousands of pre-made images for all kinds of use cases. For any common use-case, we will find an image on Docker Hub.3. Pulling an image
Downloading an image from Docker Hub is called pulling an image. The command to pull an image is docker pull, followed by the name of the image you want to download. For example, you can download the hello-world, postgres, and ubuntu image from Docker Hub using docker pull. When pulling an image using just the image name, we will always get the latest version available of the image.4. Image versions
We can find older versions of an image on hub dot docker dot com. The example you see here is for the ubuntu image. To pull a specific version, we use docker pull image-name followed by a colon and then the image-version. A version can be a number, some text, or a combination of both. For example, if we want the 22 dot 04 release of ubuntu, we can use docker pull ubuntu colon 22 dot 04 or colon jammy.5. Listing images
Now that we know how to pull images, we need a way to view the images we have available on our machine. For this, we have the docker images command, which will give us a list of all available images and tags. It will also tell us when the image was created, the size of the image on disk, and the image-id, which is a unique id to identify the image.6. Removing images
Docker only has a limited amount of space it can use on our disk. Previously we saw how to remove containers using docker container rm. Similarly, we can use docker image rm to clear space for more containers and images. A container is a running image; a side effect of this is that you can only delete an image once there are no more containers based on it. If we try to delete an image for which we still have a container on our system, we'll get the warning you can see at the bottom of the slide. This error message also includes the container's id based on the image we're trying to remove. We can use the docker container rm command to remove the container, after which we can remove the image.7. Cleaning up containers
It's common to have multiple containers based on a single image, which can make it a tedious task to one by one remove all containers before you can remove an image. To more easily clear all stopped containers, we can use docker container prune.8. Cleaning up images
Then we can use docker image prune dash a to remove all unused images. The a flag, which stands for all, makes it so that unused containers are removed and not only dangling images.9. Dangling images
A dangling image is an image that no longer has a name because the name has been re-used for another image. This frequently occurs when creating our own images. For example, if we create an image called testsql, but we find a mistake and change our image slightly, the previous testsql image will then become dangling as our new fixed image now has the testsql name.10. Summary of new commands
Here is a summary of the new commands we just saw that you can refer back to when completing the exercises.11. Let's practice!
Now it's your turn to practice pulling and removing some images. Good luck!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.