How to publish your docker image in minutes
Having your local image is awesome, but making your image public is even better. In this article I’ll explain how to push your local docker image to Docker Hub.
1. What is Docker Hub?
Docker Hub is a service provided by Docker for finding and sharing container images with your team.
2. Assumptions
You have installed Docker Desktop and have a Docker Hub account, it’s free by the way.
3. Why?
To have a repository for your image. What if you want to run outside your local machine or share with someone? The best way is to have a hub for it.
4. Alternatives
If you don’t want to use docker hub, you can use some of those below
- Amazon Elastic Container Registry (ECR)
- JFrog Artifactory
- Red Hat Quay
- Azure Container Registry
- Harbor
- Google Container Registry
- Sandboxie
- Nexus Repository Manager
- My laptop (🛑 no, please don’t do it)
5. Hands on
My account has been created at least some months ago, because this I’ve some images, all related to my video tutorials.
5.1. Dockerfile
The first step to push the image is to have the Dockerfile. In this example you’ll publish a front end part of 16-bits-zero-to-hero project.
If you need more explanation about the Dockerfile, this article will help you.
5.2. Build
Once you have the Dockerfile, it’s time to build the image
docker build -t 16bits/zero2hero-fe:0.0.1 .
5.3. Search the image
A way to search the image is using the name of the recently created image and grep, as shown below.
docker image ls | grep 16bits
6. Push to repository
⚠️ First of all verify if you are logged in. You can check typing docker login
With the first step complete, it’s time to push to docker hub. Pay attention to the image tag and your hub. In my case it has to be 16bits.
docker push 16bits/zero2hero-fe:0.0.1
7. Browse on docker hub
The image has been uploaded to hub.
8. Katacoda
8.1. What is Katacoda?
Katacoda is an incredible e-learning model that uses cloud containerization technologies like Kubernetes and Docker. (https://kuberty.io/blog/what-is-katacoda/)
After accessing the site, search for Docker and then for any scenario.
Start the scenario in order to have a machine. After the machine creation, type on terminal docker pull 16bits/zero2hero-fe:0.0.1
as shown on the picture below.
Wait until the download finishes.
Voilà, the image is there and we’re ready to run the image. To run the image use the following syntax docker run --name <alias to container> -p<HOST_PORT>:<CONTAINER_PORT> <IMAGE_ID>
or docker run --name 16bits-ui -p3000:3000 353d6c70b260
. Remember, the image id could be different in your machine.
After a while the container is running. Click on the blue link (Katacoda) to access the machine.
Change the default port 80, to the container port, ie, 3000 and hit the button Display Port.
It’s a kind of magic and the application is up and running. Since we don’t have the backend running we cannot SIGN IN, and go further.
9. References
https://pixabay.com/vectors/business-man-clock-time-lazy-lay-6719390/