docker搭建本地仓库:harbor

左手的ㄟ右手 2022-03-19 14:58 418阅读 0赞

文章目录

  • 1,离线安装 harbor
    • 启用ssl (安装前准备:证书文件)
  • 2,配置docker 仓库地址,登录harbor
  • 3,pull/push 镜像

1,离线安装 harbor


























依赖的服务 版本
docker 17.06.0-ce+
docker-compose 1.18.0
openssl Latest
离线安装包 harbor-offline-installer-v1.7.0.tgz
  • doc: https://goharbor.io/docs/2.3.0/install-config/
  • github安装包镜像下载: https://github.com/goharbor/harbor/tags

    解压后的目录

    [root@c72 harbor]# ls
    common docker-compose.clair.yml docker-compose.yml harbor.v1.7.0.tar.gz LICENSE prepare
    docker-compose.chartmuseum.yml docker-compose.notary.yml harbor.cfg install.sh open_source_license

    修改hostname( 为harbor主机名)

    [root@c72 harbor]# grep harbor.io /etc/hosts
    192.168.56.72 c72 harbor.io
    [root@c72 harbor]# grep ‘hostname =’ harbor.cfg
    hostname = harbor.io

    安装: 下载镜像, docker-compose启动所有依赖服务 (先准备好docker, docker-compose环境)

    ./prepare
    ./install.sh

    验证

    [root@c72 harbor]# docker-compose ps

    1. Name Command State Ports

    harbor-adminserver /harbor/start.sh Up (healthy)
    harbor-core /harbor/start.sh Up (healthy)
    harbor-db /entrypoint.sh postgres Up (healthy) 5432/tcp
    harbor-jobservice /harbor/start.sh Up
    harbor-log /bin/sh -c /usr/local/bin/ … Up (healthy) 127.0.0.1:1514->10514/tcp
    harbor-portal nginx -g daemon off; Up (healthy) 80/tcp
    nginx nginx -g daemon off; Up (healthy) 0.0.0.0:443->443/tcp, 0.0.0.0:4443->4443/tcp, 0.0.0.0:80->80/tcp
    redis docker-entrypoint.sh redis … Up 6379/tcp
    registry /entrypoint.sh /etc/regist … Up (healthy) 5000/tcp
    registryctl /harbor/start.sh Up (healthy)

访问80 ui端口: admin/Harbor12345
在这里插入图片描述

启用ssl (安装前准备:证书文件)

https://goharbor.io/docs/2.3.0/install-config/configure-https/

  1. #1,Generate a CA certificate private key.
  2. openssl genrsa -out ca.key 4096
  3. #2,Generate the CA certificate.
  4. openssl req -x509 -new -nodes -sha512 -days 3650 \
  5. -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=yourdomain.com" \
  6. -key ca.key \
  7. -out ca.crt
  8. #3,Generate a Server Certificate
  9. openssl genrsa -out yourdomain.com.key 4096
  10. #Generate a certificate signing request (CSR).
  11. openssl req -sha512 -new \
  12. -subj "/C=CN/ST=Beijing/L=Beijing/O=example/OU=Personal/CN=yourdomain.com" \
  13. -key yourdomain.com.key \
  14. -out yourdomain.com.csr
  15. #Generate an x509 v3 extension file.
  16. cat > v3.ext <<-EOF authorityKeyIdentifier=keyid,issuer basicConstraints=CA:FALSE keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment extendedKeyUsage = serverAuth subjectAltName = @alt_names [alt_names] DNS.1=yourdomain.com DNS.2=yourdomain DNS.3=hostname EOF
  17. #4,generate a certificate for your Harbor host
  18. openssl x509 -req -sha512 -days 3650 \
  19. -extfile v3.ext \
  20. -CA ca.crt -CAkey ca.key -CAcreateserial \
  21. -in yourdomain.com.csr \
  22. -out yourdomain.com.crt
  23. #5,Copy the server certificate and key
  24. mkdir -p /data/cert
  25. cp yourdomain.com.crt /data/cert/
  26. cp yourdomain.com.key /data/cert/
  27. #[root@c72 harbor]# grep /data/cert harbor.cfg
  28. #ssl_cert = /data/cert/server.crt
  29. #ssl_cert_key = /data/cert/server.key
  30. #6, 使得docker信任证书:The Docker daemon interprets .crt files as CA certificates and .cert files as client certificates.
  31. #证书存放路径:/etc/docker/certs.d/[yourdomain.com, yourdomain.com:port, harbor_IP:port]
  32. openssl x509 -inform PEM -in yourdomain.com.crt -out yourdomain.com.cert
  33. cp yourdomain.com.cert /etc/docker/certs.d/yourdomain.com/
  34. cp yourdomain.com.key /etc/docker/certs.d/yourdomain.com/
  35. cp ca.crt /etc/docker/certs.d/yourdomain.com/
  36. [root@c72 crts]# ls
  37. ca.crt ca.key ca.srl v3.ext yourdomain.com.cert yourdomain.com.crt yourdomain.com.csr yourdomain.com.key
  38. [root@c72 crts]# ls /etc/docker/certs.d/harbor.io/
  39. ca.crt secretkey yourdomain.com.cert yourdomain.com.key
  40. #7,重启docker服务
  41. #8,主机信任证书
  42. cp yourdomain.com.crt /etc/pki/ca-trust/source/anchors/yourdomain.com.crt
  43. update-ca-trust

2,配置docker 仓库地址,登录harbor

  1. [root@c72 harbor]# cat /etc/docker/daemon.json
  2. {
  3. "insecure-registries":["harbor.io"],
  4. "registry-mirrors": ["https://harbor.io"],
  5. "data-root":"/export/lib/docker/"
  6. }
  7. [root@c72 harbor]# cat /etc/hosts |grep harbor
  8. 192.168.56.72 c72 harbor.io
  9. [root@c72 harbor]# docker login harbor.io -u admin -p Harbor12345
  10. WARNING! Using --password via the CLI is insecure. Use --password-stdin.
  11. WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
  12. Configure a credential helper to remove this warning. See
  13. https://docs.docker.com/engine/reference/commandline/login/#credentials-store
  14. Login Succeeded
  15. #登录成功后生成的密码文件
  16. [root@c72 harbor]# cat ~/.docker/config.json
  17. {
  18. "auths": {
  19. "harbor.io": {
  20. "auth": "YWRtaW46SGFyYm9yMTIzNDU="
  21. }
  22. },
  23. "HttpHeaders": {
  24. "User-Agent": "Docker-Client/18.09.6 (linux)"
  25. }
  26. }[root@c72 harbor]#

3,pull/push 镜像

登录harbor ui 创建一个测试项目:vmware

  1. [root@c72 harbor]# docker images |grep ^vmware/ |head -2
  2. vmware/harbor-jobservice v1.1.2 ac332f9bd31c 4 years ago 163MB
  3. vmware/harbor-ui v1.1.2 803897be484a 4 years ago 183MB
  4. [root@c72 harbor]# docker images |grep ^vmware/ |head -2 |awk '{print $1":"$2}' |awk ' {print "docker tag", $0, "harbor.io/"$0}'
  5. docker tag vmware/harbor-jobservice:v1.1.2 harbor.io/vmware/harbor-jobservice:v1.1.2
  6. docker tag vmware/harbor-ui:v1.1.2 harbor.io/vmware/harbor-ui:v1.1.2
  7. [root@c72 harbor]# docker images |grep ^harbor.io/vmware/ |head -2 |awk '{print "docker push "$1":"$2}'
  8. docker push harbor.io/vmware/harbor-jobservice:v1.1.2
  9. docker push harbor.io/vmware/harbor-ui:v1.1.2

发表评论

表情:
评论列表 (有 0 条评论,418人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Docker本地仓库

    为什么需要搭建本地仓库? 1.节约带宽:因为如果用docker或阿里云官方的仓库走的互联网浪费带宽,而且慢。 2.提供资源利用和安全:因为公司内部的镜像,推送到本地仓库