As for image distribution, dockerHub is used to pull other people’s images and share their own images, which is similar to github’s mechanism, although Github has been acquired by the dreaded Microsoft.

I won’t explain how to register the DockerHub. Today’s task is to push my image into my docker push. Please watch my performance!

  • This was pushed before





Start your DockerHub journey

  • Look at imagea in Docker
docker image ls
Copy the code



  • Login dockerhub
docker login
Copy the code



sudo docker image push zhugemaing/hello-world-new:latest
Copy the code



Upload failed, rejected, why? Because the name must be the same as your username, changing the name is a try

  • Docker TAG < Image ID>
docker images ls
docker tag a4cb86cc8d6b zhugeaming/hello-world-new
Copy the code



  • Upload again
 docker image push zhugeaming/hello-world-new:latest
Copy the code






  • You can use the following command to pull the uploaded image locally



image.png

Delete local, pull down try

 docker image rm zhugeaming/hello-world-new:latest
Copy the code



 docker pull zhugeaming/hello-world-new
Copy the code



In fact, the above way is not safe

This way is basically completed, but there is a very troublesome problem, if some people with ulterior motives put some “unclean” things in the mirror, the current society, harmless to others, but to prevent others from harming themselves. In fact, dockerHub has considered this problem, let me elaborate.

  • Github connects to DockerHub via Dockerfile.





















image.png










  • Click on the trigger





  • Image is being compiled











Ha ha!

For the company, a lot of things need to be protected, so uploading to DockerHub feels insecure and unstable. For Github, we can build a private warehouse, and for DockerHub, we can also build a private warehouse.

  • Search in dockerHub



  • Install the server
Create a dockerHub private server via Registry
docker run -d -p 5000:5000 --restart always --name registry registry:2
Copy the code






  • Install and download the image inside the private server

I created a private server on one machine. If multiple servers are changed to IP addresses, Telnet another server can communicate with each other.

Docker build-t 0.0.0.0:5000/ hell-worldCopy the code






  • If it is remote, you need to add trust
sudo vi /etc/docker/daemon.js
Copy the code
The IP and port are changed according to the actual situation
{"insecure-registries": ["ip:port"]}
Copy the code



sudo vim /lib/systemd/system/docker.service

Copy the code
# Add a sentence
EnvironmentFile=/etc/docker/daemon.json

Copy the code



sudo vim /lib/systemd/system/docker.service

Copy the code
  • Push to image to private server
Docker push 0.0.0.0:5000 / hello - worldCopy the code
  • How do I check whether the upload is successful

Docs.docker.com/registry/ log in this web site, through the way of the HTTP API view







PS: This is very operable. You can easily publish your image through this.