搭建docker-registry

pull镜像

docker pull registry:2

初步运行

docker run --rm -p 5000:5000 \
  -v /Users/xixicat/registry/data:/var/lib/registry \
  -v /Users/xixicat/registry/auth:/auth \
  registry:2

访问
http://192.168.99.100:5000/v2...

创建账户密码

docker run --rm --entrypoint htpasswd registry:2 -Bbn admin admin > ~/registry/auth/htpasswd

重新运行

docker run --rm -p 5000:5000 \
  -v /Users/xixicat/registry/data:/var/lib/registry \
  -v /Users/xixicat/registry/auth:/auth \
  -e "REGISTRY_AUTH=htpasswd" \
  -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
  -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
  registry:2

添加https

  • 创建CA证书

docker run --rm -e COMMON_NAME=xixicat.com -e KEY_NAME=domain -v /Users/xixicat/registry/certs:/certs centurylink/openssl
  • 设置hosts

sudo vim /etc/hosts
192.168.99.100 xixicat.com
  • 安装证书

sudo mkdir -p /etc/docker/certs.d/xixicat.com:5000
sudo cp /Users/xixicat/registry/certs/domain.crt /etc/docker/certs.d/xixicat.com:5000/ca.crt

重启你的docker-machine

docker-machine restart yun

重新运行registry

docker run --rm -p 5000:5000 \
      -v /Users/xixicat/registry/data:/var/lib/registry \
      -v /Users/xixicat/registry/auth:/auth \
      -v /Users/xixicat/registry/certs:/certs \
      -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt\
      -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
      -e "REGISTRY_AUTH=htpasswd" \
      -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
      -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
      registry:2

检验是否成功

docker login xixicat.com:5000

jenkins推送docker镜像

在docker slave执行
图片描述

推送镜像
图片描述

输出log
图片描述

doc


codecraft
11.9k 声望2k 粉丝

当一个代码的工匠回首往事时,不因虚度年华而悔恨,也不因碌碌无为而羞愧,这样,当他老的时候,可以很自豪告诉世人,我曾经将代码注入生命去打造互联网的浪潮之巅,那是个很疯狂的时代,我在一波波的浪潮上留下...