Docker安装Registry
Registry官网
本地仓库安装无绑定oss
htpasswd网页生成密码保存到
./auth/htpasswd
,加密方式选中bcrypt,或者执行命令生成htpasswd -Bbn test 123456 > auth/htpasswd
编辑
vim docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12registry:
restart: always
image: "registry:2.6.2"
ports:
- 14005:5000
environment:
- REGISTRY_AUTH=htpasswd #授权模式
- REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm
- REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd #密码的地址
volumes:
- ./auth:/auth #密码存储的挂载卷
- ./data:/var/lib/registry #本地仓库挂载的卷启动容器
docker-compose up
创建镜像
docker tag <镜像名字> 127.0.0.1:14005<镜像名字>
登陆仓库
docker login 127.0.0.1:14005
输入账号密码或者docker login -u admin -p 123456 127.0.0.1:14005
上传镜像
docker push 127.0.0.1:14005<镜像名字>
或者拉取镜像docker pull 127.0.0.1:14005<镜像名字>
绑定oss
修改上面的第6步骤
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17registry:
restart: always
image: "registry:2.6.2"
ports:
- 14005:5000
environment:
- REGISTRY_AUTH=htpasswd
- REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm
- REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd
- REGISTRY_STORAGE=oss #必填
- REGISTRY_STORAGE_OSS_ACCESSKEYID=你的阿里云ACCESSKEYID,带oss权限 #必填
- REGISTRY_STORAGE_OSS_ACCESSKEYSECRET=你的阿里云ACCESSKEYSECRET,带oss权限 #必填
- REGISTRY_STORAGE_OSS_REGION=节点区域(oss-cn-hangzhou) #必填
- REGISTRY_STORAGE_OSS_BUCKET=buket的名字(t-docker-registry) #必填
- REGISTRY_STORAGE_OSS_ENDPOINT=t-docker-registry.oss-cn-hangzhou.aliyuncs.com #非必填
volumes:
- ./auth:/auth如果报如下错误
参考Private registry push fail: server gave HTTP response to HTTPS client
1
2
3
4
5Error response from daemon: received unexpected HTTP status: 503 Service Unavailable
或者
Error response from daemon: login attempt to http://127.0.0.1:14005/v2/ failed with status: 503 Service Unavailable
或者
Error response from daemon: Get https://112.74.51.136:14005/v2/: http: server gave HTTP response to HTTPS client设置
vim /etc/docker/daemon.json
1
2
3
4
5
6{
//这句是仓库加速地址,以前的
"registry-mirrors": ["your aliyun 加速地址"],
//添加这句,只有通过这个ip访问才不报错,如果有其他ip访问,也要加进来,不然就不用那个ip访问
"insecure-registries":["112.74.51.136:14005"]
}然后
sudo systemctl daemon-reload
重启systemctl restart docker
幻觉:失败了一次,重启又可以了?
docker registry 证书配置
部署配置
1 | registry: |
在/dockerdata/v-registry/
生成证书,注意在hostname设置时,不要忽略www
1 | [root@environment-test1 v-registry]# sudo mkdir -p certs && sudo openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key -x509 -days 365 -out certs/domain.crt |
再各个使用仓库的宿主机创建目录mkdir -p /etc/docker/certs.d/www.3sreform.com:14005
然后把生成的证书放到该目录下并改名为ca.crt
最后重启docker
sudo systemctl daemon-reload
和sudo systemctl restart docker
最后用docker login www.3sreform.com:14005 -u admin -p <密码>
测试
最后push是,镜像开头必须是www.3sreform.com