Push a Docker Container Image to Docker Hub

Joel Lord
InstructorJoel Lord
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

Now that all three tiers of your application are available in containers, you'll need to push those images to container registries. Registries are the container equivalent to repositories for your code. Registries can be public or private.

In this lesson, we'll use Docker Hub to push our images. Docker Hub repositories allow you share container images with your team, customers, or the Docker community at large.

Docker images are pushed to Docker Hub through the [docker push](https://docs.docker.com/engine/reference/commandline/push/) command. A single Docker Hub repository can hold many Docker images (stored as tags).

Images pushed to a public registry can be downloaded by using the docker pull command. Once they have the image downloaded, they can use Docker run to start each container just like you did in the previous steps.

Instructor: [0:00] The base images that you use to create your own images all come from such a registry. When you used the node image, it was available because someone initially took the time to create a Dockerfile and push it to a registry. Many registries are available for you to push your images to.

[0:19] Docker Hub is a popular registry. In fact, if you're using Docker, the base images were pulled from Docker Hub. There are also registries such as Quay, that you can install on your own infrastructure so you can keep all the images pushed to it private.

[0:35] In this course, you'll be using Docker Hub. It offers to store unlimited public images on their free tier. To create your account, just head to hub.docker.com and follow the instructions.

[0:48] Once you have an account created on Docker Hub, you are ready to store your images. The first step will be to login the registry using the docker login command, followed by the name of the registry you want connect to. In our case, this will be Docker.io.

[1:04] You will be prompted for your username and for your password. Once you are logged in, you should see a message confirming that you are indeed logged in. Now that you are logged in to Docker hub, you will be able to push your images to the registry.

[1:20] In order to push the images to the registry, you'll need to rename the images to registry/username/imagename. Because Docker assumes Docker.io as your registry, you can simply rename the images to username/imagename.

[1:38] You can use a Docker tag to rename your images. My username on Docker hub is Joe Lord, so I will rename the images accordingly.

[1:48] You never created an actual image for your database. The image that you're using is the base image from Docker hub, so no need to rename or to upload this image to your registry. You will only need with the two images you recently created.

[2:03] Now that your images have been renamed, you are ready to store those images under registry by using the Docker push command. You'll need to [?] patch in the name of the image as an argument.

[2:15] This operation will take a few seconds as every layer of your image is sent to the registry. A layer is created for each command in your Docker file. Docker will always try to reuse those cache layers whenever possible.

[2:29] The more you use Docker, the quicker those pushes will become. Now that the images are pushed to a public registry, anyone can download these images on their system by using Docker pull. Once they have the image downloaded, they can use Docker run to start each container just like you did in the previous steps.

[2:48] Just like your code repository keeps a history of all your code changes, your continue registry will keep a history of all the images. When you do a Docker push, the registry will automatically upon a :latest tag to the image.

[3:03] When someone does a pull of your image, Docker will always pull the latest tag. This can be useful, but sometimes you will want to ensure that everyone is running the same version as your container. You might have noticed that for the base containers, there was always a tag specified.

[3:20] For our node-based image, you use node 14. For your nginx image, you use nginx 117. By using a tag version of the image, you're ensuring that everyone will be using the same version of that image.

[3:34] Should you have omitted the version number in the node-based image, version 15 would have been used as this is the version that is used in the latest tag at the moment of this recording.

[3:44] In the same way, you can and should always tag your images. To tag them, you can use the Docker tag command and tag your current images to a version number. Once the images have been tagged, you can push them again to the registry.

[4:00] If you go to Docker hub, you will see the images that you pushed. If you click on any of the images, you will see the details including the versions that are available. This will be useful when you want to share your entire containerized application with your team. I'll show you how to do that in the next lesson.

egghead
egghead
~ 18 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today