Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example of how to upload a mirror image to a private repository on Docker

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Images can be easily push directly to docker's public repository, just like github, but many times in development, we do not want to disclose image files, so we need to build a private repository of docker, just like gitlab.

After building the image in the previous article, we can deploy a private image repository to store our images.

Start private Registry

It's also easy to start a private warehouse and execute commands on the server.

The copy code is as follows: docker run-d-p 5000 docker-registry 5000-- name= "docker-registry"-- restart=always-v / root/docker/registry/:/var/lib/registry/ registry

That is, the container built by the registry image is launched in the background and named docker-registry, and the port number is mapped to 5000 to 5000.

-- restart=always means that when the container stops for some reason, it restarts automatically regardless of the exit code. In addition to always, on-failure means to restart only if the exit code is not 0, and accept the parameter of restart times:-- restart=on-failture:5

-v specifies that the / root/docker/registry/ directory of the host is mounted to the container's / var/lib/registry/ directory. In this way, without entering the container, we can access the directory in the container that we are interested in on the host.

Why the / var/lib/registry/ directory?

Images and other information are stored in the repository by default. You can enter the / var/lib/registry/docker directory of the container to view the uploaded image information.

Using docker ps after successful execution of the run command, you can see that the registry service has been started:

Upload image

To upload images to a private repository, you need to add the repository address to the tag of the image:

Docker tag express-app 111.111.111.111:5000/sunhengzhe/express-app:v1

In order not to conflict with other images, you can add a namespace such as sunhengzhe, and it is best to add tag such as v1 to the image.

Note that no protocol is added to the address of the repository. The default security policy of docker requires that the repository supports https. If the server can only use http for transmission, direct upload will fail and need to be declared in the configuration file of the docker client.

Mac configuration

Apply & Restart is required after the change

Centos system

Write in the / etc/docker/daemon.json file:

{"registry-mirror": ["https://registry.docker-cn.com"]," insecure-registries ": [" [private warehouse ip:port] "]}

Then restart docker

Systemctl restart docker

Push image

After playing tag, use the push command to push:

Docker push 111.111.111.111:5000/sunhengzhe/express-app:v1

Push failed

If there is a problem with Retrying in 5 seconds and then upload failed. You can first view the logs on the server using the logs command:

Docker logs-f docker-registry

-f represents the continuous output of the contents of the file.

If filesystem: mkdir / var/lib/registry/docker: permission denied occurs, it may be a selinux problem, and you need to deal with the mount directory on the server:

Chcon-Rt svirt_sandbox_file_t / root/docker/registry/

In this example, / root/docker/registry/.

Pull the image

Just use the pull command

Docker pull 111.111.111.111:5000/sunhengzhe/express-app:v1

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report