CentOS7 搭建私有 DockerHub

警告
本文最后更新于 2022-11-23,文中内容可能已过时。

搭建企业内部使用的仓库。

安装 Docker Register

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## 使用 docker 进行 registry2 进行管理
docker pull registry

## 建立一个目录存放 docker 镜像, 默认是存放在 /tmp/registry
mkdir -p /data/Docker/registy
docker run --name docker.registry -d -p 5000:5000 -v /data/Docker/registy:/tmp/registry --restart unless-stopped  registry

docker update --restart=always <contaier_id>

docker ps -a

## 开启防火墙5000端口
systemctl restart firewalld.service
firewall-cmd --zone=public --add-port=5000/tcp --permanent
firewall-cmd --reload

## 测试访问
curl http://192.168.1.135:5000/v2/

使用

1
2
3
4
5
6
7
8
## 测试
docker tag hello-world 192.168.1.135:5000/testing
docker push 192.168.1.135:5000/testing

## 查看所有镜像
curl http://10.32.111.107:5000/v2/_catalog
## 查看镜像的所有tag
curl http://10.32.111.107:5000/v2/william-centos7-gcc9/tags/list

远程

如果出现报错

1
http: server gave HTTP response to HTTPS client

对于 CentOS 需要修改:

1
2
3
4
vim /usr/lib/systemd/system/docker.service

## 添加 --insecure-registry 10.32.111.107:5000
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock  --insecure-registry 10.32.111.107:5000

或者可以直接修改(如果是空的,需要创建)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
## 编辑 /etc/docker/daemon.json
## 添加 "insecure-registries" 里面的 "docker.williamlfang.com:58080"
sudo vim /etc/docker/daemon.json

{
  "registry-mirrors" : [
    "https://mirror.baidubce.com",
    "http://ovfftd6p.mirror.aliyuncs.com",
    "http://registry.docker-cn.com",
    "http://hub-mirror.c.163.com"
  ],
  "insecure-registries" : [
    "registry.docker-cn.com",
    "docker.mirrors.ustc.edu.cn",
    "docker.williamlfang.com:58080",
    "192.168.1.88:5000",
    "192.168.1.183:5000",
    "10.32.111.107:5000"
  ],
  "debug" : true,
  "experimental" : true,
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "1m",
    "max-file": "10"
  }
}

sudo systemctl restart docker

## 获取镜像
docker pull docker.williamlfang.com:58080/testing

Using default tag: latest
latest: Pulling from testing
Digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042
Status: Downloaded newer image for docker.williamlfang.com:58080/testing:latest
docker.williamlfang.com:58080/testing:latest

添加账户密码认证

安装 htpasswd

1
2
3
4
5
6
7
sudo yum install -y httpd-tools
mkdir /etc/docker/auth
htpasswd -Bbn tradeops passwd > /etc/docker/auth/htpasswd

## 测试是否需要认证
curl http://192.168.1.88:5000/v2/
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":null}]}

login

1
2
docker login -u tradeops 192.168.1.88:5000
docker logout 192.168.1.88:5000

添加 insecure

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
    "registry-mirrors": [
        "http://hub-mirror.c.163.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://registry.docker-cn.com"
    ],
    "insecure-registries" : [
        "192.168.1.162:5000",
        "10.32.111.107:5000"
    ]
}

airflow 处理 docker 问题

1
2
3
## 需要在 airflow 执行

docker logout 192.168.1.88:5000

相关内容

william 支付宝支付宝
william 微信微信
0%