Sharing images on Docker HubEstimated reading time: 3 minutes
- Orientation and setup
- Containerizing an application
- Deploying to Kubernetes
- Deploying to Swarm
- Sharing images on Docker Hub
- Work through containerizing an application in Part 2.
At this point, you’ve built a containerized application in Part 2, and potentially run it on Kubernetes in Part 3 or Swarm in Part 4, all on your local development machine thanks to Docker Desktop. The final step in developing a containerized application is to share your images on a registry like Docker Hub, so they can be easily downloaded and run on any destination cluster.
Setting Up Your Docker Hub Account
If you don’t yet have a Docker ID, follow these steps to set one up; this will allow you to share images on Docker Hub.
Visit the Docker Hub sign up page, https://hub.docker.com/signup.
Fill out the form and submit to create your Docker ID.
Click on the Docker icon in your toolbar or system tray, and click Sign In / Create Docker ID. Fill in your new Docker ID and password. If everything worked, your Docker ID will appear in the Docker Desktop dropdown in place of the ‘Sign In’ option you just used.
You can do the same thing from the command line by typing
Creating and Pushing to a Docker Hub Repository
At this point, you’ve set up your Docker Hub account and have connected it to your Docker Desktop. Now lets make our first repo, and share our bulletin board app there.
Click on the Docker icon in your menu bar, and navigate to Repositories -> Create.... You’ll be taken to a Docker Hub page to create a new repository.
Fill out the Repository Name as
bulletinboard. Leave all the other options alone for now, and click Create at the bottom.
Now we’re ready to share our image on Docker Hub, but there’s one thing we must do first: images must be namespaced correctly to share on Docker Hub. Specifically, images must be named like
<Docker Hub ID>/<Repository Name>:<tag>. We can relabel our
bulletinboard:1.0image like this (of course please replace
gordonwith your Docker ID):
docker image tag bulletinboard:1.0 gordon/bulletinboard:1.0
Finally, push your image to Docker Hub:
docker image push gordon/bulletinboard:1.0
Visit your repository in Docker Hub, and you’ll see your new image there. Remember, Docker Hub repositories are public by default.
Having trouble pushing? Remember, you must be signed in to Docker Hub through Docker Desktop or the command line, and you must also name your images correctly, per the above steps. If the push seemed to work but you don’t see it in Docker Hub, refresh your browser after a couple of minutes and check again.
Now that your image is available on Docker Hub, you’ll be able to run it anywhere; if you try to use it on a new cluster that doesn’t have it yet, Docker will automatically try and download it from Docker Hub. By moving images around in this way, we no longer need to install any dependencies except Docker and our orchestrator on the machines we want to run our software on; the dependencies of our containerized applications are completely encapsulated and isolated within our images, which we can share via Docker Hub in the manner above.
Another thing to keep in mind: at the moment, we’ve only pushed your image to Docker Hub; what about your Dockerfiles, Kube YAML and stack files? A crucial best practice is to keep these in version control, perhaps alongside your source code for your application, and add a link or note in your Docker Hub repository description indicating where these files can be found, preserving the record not only of how your image was built, but how it’s meant to be run as a full application.docker hub, push, images