由于速度或存储或业务问题,可能会需要自建docker仓库,这里简单记录下通过docker
的 registry
镜像自建docker仓库。
registry仓库: https://hub.docker.com/_/registry
操作文档: https://docs.docker.com/registry/deploying/
最新版镜像拉取命令: docker pull registry:latest
一句话部署:
docker run -d -p 5000:5000 --restart=always --name registry registry:2
还有一些其他的配置选项以及共享卷配置等。
docker run -d \
-p 5000:5000 \
--restart=always \
--name registry \
-v /mnt/registry:/var/lib/registry \
registry:2
/var/lib/registry
是容器内存储镜像的目录,将该目录映射到宿主机的/mnt/registry
目录中。(牢记一点 : 容器销毁后容器内的所有资源都是会被销毁的,所有需要持久化的数据都需要选择外部的共享卷来存储
)
docker run -d \
--restart=always \
--name registry \
-v "$(pwd)"/certs:/certs \
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
-p 443:443 \
registry:2
宿主机内的端口可能并不是443,则需要通过nginx
来转发,通过nginx
也需要增加ssl
相关的配置。
server {
listen 443 ssl;
server_name ***.***.com;
ssl_certificate cert/cert.crt;
ssl_certificate_key cert/ert.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
ssl_prefer_server_ciphers on;
charset utf-8;
location / {
proxy_pass https://localhost:8375;
client_max_body_size 1000m;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
$ mkdir auth
$ docker run \
--entrypoint htpasswd \
httpd:2 -Bbn testuser testpassword > auth/htpasswd
docker container stop registry
docker run -d \
-p 5000:5000 \
--restart=always \
--name registry \
-v "$(pwd)"/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
-v "$(pwd)"/certs:/certs \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
registry:2
docker login myregistrydomain.com:5000
docker-compose
创建仓库docker-compose.yml
registry:
restart: always
image: registry:2
ports:
- 5000:5000
environment:
REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt
REGISTRY_HTTP_TLS_KEY: /certs/domain.key
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
volumes:
- /path/data:/var/lib/registry
- /path/certs:/certs
- /path/auth:/auth
docker pull ubuntu:16.04
docker tag ubuntu:16.04 localhost:5000/my-ubuntu
3.推送镜像到仓库
docker push localhost:5000/my-ubuntu
docker image remove ubuntu:16.04
docker image remove localhost:5000/my-ubuntu
docker pull localhost:5000/my-ubuntu
官网: https://goharbor.io/ 下载: https://goharbor.io/docs/2.8.0/install-config/download-installer/
下载后修改 harbor.yml 配置文件即可。
转载请注明出处: https://chrunlee.cn/article/docker-hub-registry.html