/var/lib/registry
路徑,並volumn
到宿主機Registry
服務開放到 Localhost
之外的域要求TLS加密Registry
默認監聽 5000 端口1. 單服務模式啓動node
docker run -d --name registry --hostname registry.example.com \ -e "REGISTRY_STORAGE_DELETE_ENABLED=true" \ -e "REGISTRY_AUTH: htpasswd" \ -e "REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd" \ -e "REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm" \ -e "REGISTRY_HTTP_TLS_KEY: /etc/certs/domain.key" \ -e "REGISTRY_HTTP_TLS_CERTIFICATE: /etc/certs/domain.crt" \ -p 5000:5000 \ -v /etc/certs:/etc/certs \ -v /srv/registry/auth:/auth \ -v /srv/registry/storage:/var/lib/registry \ --restart=always registry:2
2. Compose服務編排模式(推薦方式)docker
docker pull registry:2 ####################### 多行命令開始 ############################### cat >> docker-compose.yaml <<EOF version: '2' services: Registry: image: 'registry:2' container_name: 'registry' hostname: 'registry.example.com' restart: always ports: - '5000:5000' environment: REGISTRY_STORAGE_DELETE_ENABLED: 'true' REGISTRY_AUTH: htpasswd REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm REGISTRY_HTTP_TLS_KEY: /etc/certs/domain.key REGISTRY_HTTP_TLS_CERTIFICATE: /etc/certs/domain.crt volumes: - /etc/certs:/etc/certs - /srv/registry/auth:/auth - /srv/registry/storage:/var/lib/registry EOF ####################### 多行命令結束 ############################### docker-compose up -d
TLS加密可採用自簽名證書bash
sudo mkdir /etc/certs cd /etc/certs # 若是簽發對象仍是個IP而不是域名的話 # 自簽名證書須要有個備選的IP SANS校驗信息 sudo sed -i '/\[ v3_ca \]/a\subjectAltName = IP:121.40.145.76' /etc/pki/tls/openssl.cnf # CentOS7環境下 sudo openssl req -newkey rsa:4096 -nodes -sha256 -keyout domain.key -x509 -days 365 -out domain.crt # 其中Common Name輸入 registry.example.com sudo openssl dhparam -out dhparam.pem 1024 # 生成DHE參數文件加強ssl加密
Registry的自簽名證書須要手動導入到客戶端Docker Daemon的根證書信任列表:dom
不作TLS加密,使用普通http通訊(不推薦)ui
Registry
不支持 basic authentication
Docker Damon
配置啓動選項 DOCKER_OPTS="--insecure-registry registry.example.com:5000"
## 鏡像指向私有registry兩種方式 ## docker tag 本地鏡像 registry_url[:port]/namespace/imagename[:tag] # tag一個本地鏡像到registry方式 docker build -t registry_url[:port]/namespace/imagename[:tag] . # 直接build鏡像到registry方式 docker push registry_url[:port]/namespace/imagename[:tag] # 推送鏡像到倉庫 docker pull registry_url[:port]/namespace/imagename[:tag] # 拉取鏡像