Get startedGet started for free

Distributing Docker Images

1. Distributing Docker Images

In the previous lesson, we learned about the official Docker images registry and how we can pull images from it. This is just one way images are distributed. Now, we will learn how to share images with just a few people or a broader community. Either by sending docker images like we would send any other file or using a Docker registry server.

2. Private Docker registries

First, we'll have a look at private Docker registry servers. The Docker organization maintains the official Docker images registry. Other Docker registries work the same way but are under the control of another person or group. This means there are no guarantees that the images will work or are safe to use. Images from any registry other than the one from the official Docker organization are easily recognizable because their name starts with the URL of the private Docker registry they come from. For example, the image we see here comes from dockerhub dot myprivateregistry dot com. Downloading or pulling an image from a private registry is also done using Docker pull. Because the image name includes the Docker registry URL, the image will automatically be pulled from the correct registry. For example, to pull the previously mentioned image, use Docker pull followed by the full name of the image. Here too, we can append a colon followed by the version.

3. Pushing to a registry

Now that we know how to pull images from a custom registry, let's look at how to upload or push an image to a Docker registry. The command for this is Docker image push followed by the image name. To push an image to a specific registry, we only have to make sure the image name starts with the name of the registry we want to push to. We can do this by renaming the image using Docker tag. For example, if we have the image classify underscore spam colon v1 and we want to push it to docker dot myprivateregistry dot com, we would use Docker tag followed by the image we'd like to rename and then the desired new name including the url of the private registry. After renaming the image, we can use Docker image push followed by the image name to push the image to our private registry.

4. Authenticating against a registry

While the Docker official images can be pulled without authentication, anybody creating a private Docker registry can make it private and require authentication. The standard way to secure private Docker registries requires users to log in. We do this with the Docker login command followed by the private registry we want to authenticate for. For example, Docker login dockerhub dot myprivateregistry dot com, the URL we authenticate for should be the same as the URL we put in front of an image name.

5. Docker images as files

If, instead of using a Docker registry, we want to send a Docker image to just a few people, it can be easier to send the image as a file. Use the save command to save a Docker image to a file. This will create a minimized file which we can then share like any other file. We can pass the desired filename to the save command using the minus o flag. To load the file, we use the load command, passing the filename using the minus i flag.

6. Summary of new commands

Here is a summary of the new commands we just saw that you could refer back to when completing the exercises.

7. Let's practice!

Now it's your turn, let's practice pushing and pulling to a private repository and creating a file from our Docker images.