This is part 4 of the Docker Tutorial Series.
In this session, we shall look at working with the Docker registry. Some of this has already been covered, but it is nice to go through these commands again plus this session has a little bit more on the Docker Registry (Hub).
Recollect that the Docker toolset consists of:
- Docker Daemon
- Docker Client
- Docker Hub
The Docker Architecture diagram is reproduced below again:
Let us focus on the Registry part in the diagram. The Registry is also called the Hub. So for the purpose of this document, the 2 terms are interchangeable.
Docker hosts public repositories called the Docker Registry (Hub) where you can find a list of public Docker images for your use. This is handy, since a lot of developers have worked hard to get the images ready for us and all we need to do is pull those images and start launching containers based on them.
The implications of this for the developer is huge. It cuts down your time drastically in downloading/setting up applications that you want to have running locally as fast as possible. For e.g. consider that you have to setup MySQL. One option available to you is to go down the traditional path and download the installer binary from the official MySQL site. Then follow the instructions to set things up and more. You know that this process is time consuming and error prone.
By now, you would have realised that a standard format for containers makes things not just easy and quick with a toolchain like Docker but you are also sure that it’s going to run not just on your machine but if you need to give that image to someone else, you are confident of it running well there too.
So to summarize, do the following steps:
- Visit the Docker Hub : https://hub.docker.com
- Do sign up for the hub, this can help you push your own Docker images into the Hub too.
- Check out the above Hub site. See the huge list of Docker images available for almost any software that you have used so far.
Assuming you are logged in with your Account (Search actually works without an account too!) — try searching for any images via the Web Search box as shown below:
For e.g. type in Java, press <return> and see the list of repositories that are returned.
The screenshot below is the first repository that was listed:
Notice the stars and the downloads. It gives you a good idea of its popularity.
Click on that repository and you will be lead to a page that will show various images (by their tags) and instructions for running a container based on that image and so on.
Shown below is a screenshot of the images and their tags:
Try It Out : In the image above, search for the latest tag. It will be there. Click that and it will lead you to a Dockerfile (more on that in another hands-on). Even if you do not understand all aspects of the Dockerfile, do take a look slowly and you will begin to see a pattern image. Hint : OS -> Software -> Any other dependencies , etc are slowly built one by one into your image.
Now that you are familiar with IMAGES and their TAGS, it should be clear to you that those are the only two pieces of information that you need to pull down an image locally to your step.
You can do that via the docker pull command as shown below:
$ docker pull java
$ docker pull java:latest
$ docker pull java:8
and so on.
You can check out the list of images that you have locally via the docker images command:
$ docker images
Understand the output. It will have REPOSITORY and the TAG in the output result.
Now that you have a local image, you can launch a container via :
$ docker run <imagename>:<tag>
Earlier we saw how we could search for Docker images via the Docker Hub Web interface. We can do that via the docker command line too.
$ docker search <TERM>
$ docker search httpd
$ docker search java
$ docker search mysql