国区现在已经完全访问不了docker hub的镜像了,对于使用来说很不方便。各个大厂的公共镜像站也陆续下降,除了收费镜像服务外,稍有几个能稳定用的。这里用一个便宜的vps把要常用到的镜像都harbor缓存过来或者直当接镜像库使用
安装docker
外网服务器安装docker服务,docker安装参考:
部署 docker的仓库镜像
docker-compose.yml配置文件
version: '3.8'
services:
registry-server:
image: registry:2.8.2
restart: always
ports:
- 5000:5000
environment:
REGISTRY_HTTP_HEADERS_Access-Control-Allow-Origin: '[http://registry-ui.example.com]'
REGISTRY_HTTP_HEADERS_Access-Control-Allow-Methods: '[HEAD,GET,OPTIONS,DELETE]'
REGISTRY_HTTP_HEADERS_Access-Control-Allow-Credentials: '[true]'
REGISTRY_HTTP_HEADERS_Access-Control-Allow-Headers: '[Authorization,Accept,Cache-Control]'
REGISTRY_HTTP_HEADERS_Access-Control-Expose-Headers: '[Docker-Content-Digest]'
REGISTRY_STORAGE_DELETE_ENABLED: 'true'
volumes:
- ./registry/data:/var/lib/registry
- ./registry-config.yml:/etc/docker/registry/config.yml
- ./registry-htpasswd:/etc/docker/registry/htpasswd
container_name: registry-server
registry-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]
Access-Control-Allow-Origin: ['http://127.0.0.1:8000']
Access-Control-Allow-Methods: ['HEAD', 'GET', 'OPTIONS', 'DELETE']
Access-Control-Allow-Headers: ['Authorization', 'Accept', 'Cache-Control']
Access-Control-Max-Age: [1728000]
Access-Control-Allow-Credentials: [true]
Access-Control-Expose-Headers: ['Docker-Content-Digest']
auth:
htpasswd:
realm: basic-realm
path: /etc/docker/registry/htpasswd
proxy:
remoteurl: https://docker.1ms.run
这里的proxy.remoteurl: 配置成官网的仓库地址即可
registry-htpasswd 参考(账号:admin/密码:admin123):
admin:$2y$05$c8x6RzaYl27VK7Vqi2SJC.nBrMQ1pp.X4/7puDPy98jlRlZmoNfpm
registry-htpasswd 密码本生成方式:
【默认文件的账号密码为:admin/admin123】
# 生成新的密码文件,-c参数即创建文件, -B参数使用bcrypt对文件进行加密
htpasswd -B -c ${htpasswd_file_path} ${user_name_1}
# 在已有的密码文件中追加新的用户密码
htpasswd -B ${htpasswd_file_path} ${user_name_2}
# 删除已有用户
htpasswd -D ${htpasswd_file_path} ${user_name_2}
配置docker的daemon
.json,添加服务器地址和端口
编辑docker配置文件 /etc/docker/daemon.json
(如果没有则创建一个)
内容:
{
"registry-mirrors":["http://外网ip:端口"],
"insecure-registries":["外网ip"]
}
重启docker服务
sudo systemctrl docker restart
拉取镜像
sudo docker pull 镜像名
关联内容:
http://blog.xqlee.com/article/2502221232315848.html