1. Dependence
First, you need to install the docker environment. For reference: Docker installation of different distributions of Linux
Secondly, you need to prepare your own Linux server, which can facilitate your image pull and upload.
2. Text
2.1 Create a folder
Used to store your warehouse data
sudo mkdir -p /opt/docker-registry/data
2.2 Running the Docker warehouse container
This command will pull the latest registry:2 image from Docker Hub, run the container in the background, map the local port 5000 to port 5000 in the container, so that other hosts can access the warehouse
sudo docker run -d -p 5000:5000 --name registry -v /opt/docker-registry/data:/var/lib/registry registry:2
2.3 Configure the Docker client
Edit the Docker configuration file /etc/docker/daemon.json,
If the file does not exist, create a new one and add the following content to it.
This command will allow the Docker client to send unencrypted HTTP requests to your repository .
Note: Remember to replace "my-registry-domain.com" with the IP address or domain name of your remote warehouse
{
"insecure-registries" : ["my-registry-domain.com:5000"]
}
2.4 Restart the Docker service
sudo systemctl restart docker
2.5 Local image push warehouse
Note: Remember to replace "my-registry-domain.com" with your repository's IP address or domain name
sudo docker tag <image-name> my-registry-domain.com:5000/你的镜像名称
sudo docker push my-registry-domain.com:5000/你的镜像名称
2.6 Pull warehouse image locally
sudo docker pull 你的仓库IP或域名:5000/你的镜像名称
Note: If your warehouse requires authentication, you need to log in first
sudo docker login 你的仓库IP或域名:5000
3. Expand
The Docker warehouse supports two authentication mechanisms: HTTP-based authentication (Basic Authentication) authentication and Token-based authentication (Token Authentication).
If you do not set an account password when creating a warehouse, then by default, the Docker warehouse will enable the Token-based authentication mechanism. This mechanism allows you to access repositories without a username and password, using tokens instead of authentication.
If you need to disable token authentication, you can enable basic authentication in your repository by following these steps:
1. Create a password file in the Docker warehouse container
sudo mkdir -p /opt/docker-registry/auth
sudo docker run --entrypoint htpasswd registry:2 -Bbn <username> <password> > /opt/docker-registry/auth/htpasswd
This command will create a password file using the registry:2 image and save it to /opt/docker-registry/auth/htpasswd. Remember to replace "<username>" and "<password>" .
2. Stop and delete the original Docker repository container and create a new one to enable basic authentication
sudo docker stop registry
sudo docker rm registry
sudo docker run -d \
-p 5000:5000 \
--name registry \
--restart always \
-v /opt/docker-registry/data:/var/lib/registry \
-v /opt/docker-registry/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
registry:2