Docker Hub
Last updated
Last updated
Github is probably familiar to you, so what is Docker Hub? Are the Hub in "Docker Hub" and the "hub" in "github" the same? Let's find out together
Docker Hub is a service provided by Docker that allows searching and sharing container images. The main features of Docker Hub are:
Repositories: Push và pull container images.
Teams & Organizations : Manage access to private repositories of container images.
Official Images : Pull uses high quality Docker container images.
Publisher Images : Pull and use container images provided by other vendors.
Builds : Automatically create container images from GitHub and Bitbucket. Push them to Docker Hub.
Webhooks : Activate actions after successfully pushing a repository to Docker Hub with other services.
To use Docker Hub, sign up for an account here .
If your computer does not have Docker installed, you can install it by following the instructions here , or read this article.
If your computer has docker installed, open the terminal and run the command:
then enter username and password. If the result you get is
then that's ok. Now we can create docker images.
First, we need to create a repository on Docker Hub, this will be the place to store our images.
To create a repository, log in to Docker Hub and visit the page: https://hub.docker.com/repository/create
For example, here I have created a repository called 2020-09-test
Now I will show you how to create an image locally and push it to the repository. Extremely simple.
First of all, we will create a Dockerfile
A Dockerfile file will be created like so
Let's try this build
So we have created an image locally with id 9736d7eb35b9
. Try running the image:
So our image is running with a CONTAINER ID of c2c4f119039a
.
Now let's commit and push the image to Docker Hub
As a result, after the push is completed, we have an image with the tagname latest
Now download it and try it out
It's delicious, let's try running the image:
It seems simple. But to learn more deeply, please find out here . Docker Hub's documentation is really misleading to users
In addition to pushing as in section 2, we can also connect Docker Hub's repository to Github. Then, instead of pushing the image to Docker Hub, we can push the code to github, and build the image on the Docker Hub interface.
First, you need to connect your Github account on Docker Hub here: https://hub.docker.com/settings/linked-accounts
Once connected, go to the repository and select the Builds tag:
After clicking on the Github icon, select the repo you want to save the source code for your image:
Click Save and Build, so your source code on Github will be built into an image. Too easy, right?