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

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

The image can be easily pushed directly to the Docker public repository, just like GitHub, but we often don't want to make the image file public during development. In this case, we need to build a Docker private repository, just like GitLab.

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

Start a private registry

Starting a private repository is also very simple. Execute the command on the server

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

That is, the container built by the registry image is started 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 will automatically restart regardless of the exit code. In addition to always , there is also on-failure , which means restarting only when the exit code is not 0, and accepts the restart count parameter: --restart=on-failture:5

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

Why /var/lib/registry/ ?
By default, the repository stores images and other information in the /var/lib/registry/docker directory of the container. You can enter this directory to view the uploaded image information.

After successfully executing the run command, use docker ps to see that the registry service has been started:

Upload image

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

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

In order to avoid conflicts with other images, you can add a namespace such as sunhengzhe . In addition, it is best to tag the image such as v1 .

Note that the repository address does not include the protocol part. The default security policy of Docker requires that the repository supports https . If the server can only use http transmission, direct upload will fail. It needs to be declared in the configuration file of the Docker client.

Mac configuration

After the change, you need to Apply & Restart

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 typing tag , use the push command to push it:

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

Push failed

If the problem of Retrying in 5 seconds and then uploading fails occurs. You can first use the logs command on the server to view the logs:

docker logs -f docker-registry

-f means continuous output of file contents.

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

chcon -Rt svirt_sandbox_file_t /root/docker/registry/

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

Pull the image

Use the pull command

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

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed steps to build a Docker Registry private warehouse
  • Detailed steps for Docker to build a local private warehouse
  • Docker private repository management and deletion of images in local repositories
  • How to query or obtain images in a private registry
  • Docker tutorial: Private warehouse detailed explanation
  • Detailed explanation of centos7 docker1.12 installation of private warehouse
  • Detailed explanation of the easiest way to build a Docker private warehouse
  • Detailed explanation of the construction and use of Docker private warehouse
  • Detailed explanation of CentOS 7: Docker private warehouse construction and use
  • Detailed explanation of the construction and interface management of Docker private warehouse

<<:  mysql5.7.19 winx64 decompressed version installation and configuration tutorial

>>:  Detailed explanation of the cache implementation principle of Vue computed

Recommend

Pros and Cons of Vite and Vue CLI

There is a new build tool in the Vue ecosystem ca...

How to install and configure the supervisor daemon under centos7

Newbie, record it yourself 1. Install supervisor....

W3C Tutorial (5): W3C XML Activities

XML is designed to describe, store, transmit and ...

Implementation of Single Div drawing techniques in CSS

You can often see articles about CSS drawing, suc...

JavaScript explains the encapsulation and use of slow-motion animation

Implementing process analysis (1) How to call rep...

Docker container data volume named mount and anonymous mount issues

Table of contents What is a container data volume...

Use vue2+elementui for hover prompts

Vue2+elementui's hover prompts are divided in...

Use of Linux stat command

1. Command Introduction The stat command is used ...

How to transfer files between Windows and Linux

File transfer between Windows and Linux (1) Use W...

Use of Vue filters and custom instructions

Table of contents Filters 01.What is 02. How to d...

WeChat Mini Program implements the likes service

This article shares the specific code for the WeC...