Build a docker private warehouse to configure username and password


1. System configuration

Server: centos 7
Client: Windows 10

2. Build the server

# 下载 registry
docker pull registry
# 挂载相关的配置
mkdir -p  /docker/registry/auth
# 生成账号密码:name password123
docker run --entrypoint htpasswd registry:latest -Bbn name password123  >> /docker/registry/auth/htpasswd
# 设置配置文件
mkdir -p  /docker/registry/config
vim  /docker/registry/config/config.yml
# 输入以下文件

version: 0.1
log:
  fields:
    service: registry
storage:
  delete:
    enabled: true
  cache:
    blobdescriptor: inmemory
  filesystem:
    rootdirectory: /var/lib/registry
http:
  addr: :5000
  headers:
    X-Content-Type-Options: [nosniff]
health:
  storagedriver:
    enabled: true
    interval: 10s
threshold: 3

start up:

docker run -d -p 5005:5000 --restart=always  --name=registry \
-v /docker/registry/config/:/etc/docker/registry/ \
-v /docker/registry/auth/:/auth/ \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
-v /docker/registry/:/var/lib/registry/ \
registry

3. Configure the Windows client

1、登录搭建的私有docker仓库
docker login 106.114.114.114:5005
输入用户名密码,这个地方会报错,解决办法会贴截图
Error response from daemon: Get https://106.114.114.114:5005/v2/: http: server gave HTTP response to HTTPS client
2、标记本地镜像
# docker tag 选择一个镜像 服务端IP:端口/镜像名:版本
docker tag redis:latest 106.114.114.114:5005/redis:latest
3、推送镜像到仓库
docker push 106.114.114.114:5005/redis:latest

Insert picture description here

4. Configure centos client

1、# 一样的操作,我们先登录
docker login 106.114.114.114:5005
# Error response from daemon: Get https://106.114.114.114:5005/v1/users/: dial tcp 106.114.114.114:5005: i/o timeout
# 解决:https://blog.csdn.net/quanqxj/article/details/79479943
# Error response from daemon: Get https://106.114.114.114:5005/v2/: http: server gave HTTP response to HTTPS client
# 解决:
# vim /etc/docker/daemon.json
# 添加如下内容
# {"insecure-registries":["106.114.114.114:5005","106.114.114.114"]}
2、标记本地镜像
# docker tag 选择一个镜像 服务端IP:端口/镜像名:版本
docker tag redis:latest 106.114.114.114:5005/redis:latest
3、推送镜像到仓库
docker push 106.114.114.114:5005/redis:latest

Insert picture description here

5. Check the effect

1. Go to the server to view:

cd /docker/registry/docker
# 会有一个docker的文件夹
tree

Insert picture description here
Insert picture description here
2. Go to the client to test:

# 先将我们生成的镜像 rmi 掉
docker rmi 106.114.114.114:5005/redis:latest
# 拉取私库镜像
docker pull 106.114.114.114:5005/redis

3. View all the images in the private container:

curl -u "name:password123" -X GET http://106.114.114.114:5005/v2/_catalog

Insert picture description here

This has been successful

6, notes

1. This article is basically not original, the original blogger's client is only CentOS, mine is Windows. When there is a need for the client to be centos, you can directly look at the original blogger. By the way, if you follow the above operation, it is also strongly recommended to read the original blogger’s article. There are many private libraries and other knowledge points to learn
shida_csdn: https:// blog.csdn.net/shida_csdn/article/details/78435971

2. The next article provides building docker private library and configuring certificate mode

3. I am well aware that the tutorials provided above are still not complete, and there will still be problems in some places.
Provide a group: 807770565, welcome everyone to come in and chat
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_38637558/article/details/99603071