2023年6月21日发(作者:)

详解基于Harbor搭建Docker私有镜像仓库什么是 Harbor?第⼀次使⽤这个的时候是刚进公司处理的第⼀个任务的时候,发现 Harbor 就是⼀个⽤于存储和分发 Docker 镜像的企业级Registry 服务器。⽹上找到⼀个 Harbor 的架构图:环境准备1、⾃⼰在腾讯云买的服务器(CentOS7.3)2、Docker 版本:17.05.0-ce3、Docker-compose:1.17.14、Harbor:1.1.2安装 Docker因为系统是 CentOS 7.3 ,内核啥的都已经是 3.10,所以不⽤担⼼内核升级的问题,⼀些操作啥的在 7.x 上操作也很⽅便。yum update //系统版本更新vim /etc/.d/ //添加以下内容[dockerrepo]name=Docker Repositorybaseurl=/repo/main/centos/7/enabled=1gpgcheck=1gpgkey=/gpg//下⾯安装 Docker 引擎yum install docker-engine -y//安装docker引擎,此步也可作为更新docker版本的操作:先#systemctl stop docker 停⽌docker服务,再#yum install docker-engine 更新docker版本systemctl enable esystemctl start docker //启动docker守护进程docker info //查看docker运⾏情况docker -v //查看版本信息修改 Docker 配置⽂件 /etc/default/docker 如下:复制代码 代码如下:DOCKER_OPTS="--registry-mirror=" //换成国内的镜像加速源,不然拉取镜像简直龟速,不想在吐槽了使⽤

service docker restart 重启 Docker 服务即可。或者⽤官⽅提供的⽅式:复制代码 代码如下:curl -sSL /daotools/set_ | sh -s [/code]安装 Docker-compose如果是想直接命令安装也⾏,下载指定版本的docker-compose对⼆进制⽂件赋可执⾏权限chmod +x /usr/local/bin/docker-compose测试下docker-compose是否安装成功docker-compose --version出现如下docker-compose version 1.17.1, build 6d101fb但是,这种⽅法简直龟速,幸好还有种⽅法,这种需要通过 Python 的 pip 安装安装 pipwget --no-check-certificate /packages/source/s/setuptools/ -vxf setuptools-1.4.2python2.7 install //因为服务器⾃带 Python 2.7easy_install-2.7 pip安装 docker composepip install docker-composedocker-compose --version //测试安装是否成功安装 Harborwget /vmware/harbor/releases/download/v1.1.2/#离线安装包,也是龟速,把这个下载链接⽤迅雷下载,速度却贼快,嘿嘿,然后再传到服务器上去,整个过程快很多!tar -zxvf 解压缩之后,进⼊⽬录下会看到 ⽂件,该⽂件就是 Harbor 的配置⽂件。## Configuration file of Harbor# hostname设置访问地址,可以使⽤ip、域名,不可以设置为127.0.0.1或localhosthostname = 115.159.227.249 #这⾥我先配置我的服务器IP地址# 访问协议,默认是http,也可以设置https,如果设置https,则nginx ssl需要设置onui_url_protocol = http# mysql数据库root⽤户默认密码root123,实际使⽤时修改下db_password = root123#Maximum number of job workers in job servicemax_job_workers = 3#Determine whether or not to generate certificate for the registry's token.#If the value is on, the prepare script creates new root cert and private key#for generating token to access the registry. If the value is off the default key/cert will be used.#This flag also controls the creation of the notary signer's ize_crt = on#The path of cert and key files for nginx, they are applied only the protocol is set to httpsssl_cert = /data/cert/_cert_key = /data/cert/#The path of secretkey storagesecretkey_path = /data#Admiral's url, comment this attribute, or set its value to NA when Harbor is standaloneadmiral_url = NA#NOTES: The properties between BEGIN INITIAL PROPERTIES and END INITIAL PROPERTIES#only take effect in the first boot, the subsequent changes of these properties#should be performed on web ui#************************BEGIN INITIAL PROPERTIES************************#Email account settings for sending out password resetting emails.#Email server uses the given username and password to authenticate on TLS connections to host and act as identity.#Identity left blank to act as _identity =email_server = il_server_port = 25email_username = sample_admin@il_password = abcemail_from = admin email_ssl = false##The initial password of Harbor admin, only works for the first time when Harbor starts.#It has no effect after the first launch of Harbor.# 启动Harbor后,管理员UI登录的密码,默认是Harbor12345harbor_admin_password = Harbor12345# 认证⽅式,这⾥⽀持多种认证⽅式,如LADP、本次存储、数据库认证。默认是db_auth,mysql数据库认证auth_mode = db_auth#The url for an ldap _url = ldaps://#A user's DN who has the permission to search the LDAP/AD server.#If your LDAP/AD server does not support anonymous search, you should configure this DN and ldap_search_pwd.#ldap_searchdn = uid=searchuser,ou=people,dc=mydomain,dc=com#the password of the ldap_searchdn#ldap_search_pwd = password#The base DN from which to look up a user in LDAP/ADldap_basedn = ou=people,dc=mydomain,dc=com#Search filter for LDAP/AD, make sure the syntax of the filter is correct.#ldap_filter = (objectClass=person)# The attribute used in a search to match a user, it could be uid, cn, email, sAMAccountName or other attributes depending on your LDAP/AD ldap_uid = uid#the scope to search for users, 1-LDAP_SCOPE_BASE, 2-LDAP_SCOPE_ONELEVEL, 3-LDAP_SCOPE_SUBTREEldap_scope = 3#Timeout (in seconds) when connecting to an LDAP Server. The default value (and most reasonable) is 5 _timeout = 5# 是否开启⾃注册self_registration = on# Token有效时间,默认30分钟token_expiration = 30# ⽤户创建项⽬权限控制,默认是everyone(所有⼈),也可以设置为adminonly(只能管理员)project_creation_restriction = everyone#Determine whether the job service should verify the ssl cert when it connects to a remote registry.#Set this flag to off when the remote registry uses a self-signed or untrusted _remote_cert = on#************************END INITIAL PROPERTIES************************启动 harbor,修改完配置⽂件后,在的当前⽬录执⾏./,Harbor服务就会根据当期⽬录下的开始下载依赖的镜像,检测并按照顺序依次启动各个服务。登录 Web Harbor , 输⼊⽤户名 admin,默认密码(或已修改密码)登录系统。我们可以看到系统各个模块如下:项⽬:新增/删除项⽬,查看镜像仓库,给项⽬添加成员、查看操作⽇志、复制项⽬等⽇志:仓库各个镜像create、push、pull等操作⽇志系统管理1. ⽤户管理:新增/删除⽤户、设置管理员等2. 复制管理:新增/删除从库⽬标、新建/删除/启停复制规则等3. 配置管理:认证模式、复制、邮箱设置、系统设置等其他设置1. ⽤户设置:修改⽤户名、邮箱、名称信息2. 修改密码:修改⽤户密码注意:⾮系统管理员⽤户登录,只能看到有权限的项⽬和⽇志,其他模块不可见。我们要尝试下能不能把⾃⼰ Docker ⾥⾯的镜像 push 到 Harbor 的 library ⾥来(默认这个 library 项⽬是公开的,所有⼈都可以有读的权限,都不需要 docker login 进来,就可以拉取⾥⾯的镜像)。注意:为了后⾯留坑,我这⾥先 在⾃⼰的 e 中添加仓库:(这是个坑,建议你先按照我说的做,不然下⾯可能会⼀直登录不上)vim /usr/lib/systemd/system/e#⾥⾯的这⾏修改为:(其实就是添加 --insecure-registry 115.159.227.249 )ExecStart=/usr/bin/dockerd --insecure-registry 115.159.227.249添加完了后重新启动 docker:systemctl daemon-reload && systemctl enable docker && systemctl start docker启动 docker 服务:service docker start登录:(为了测试下能否登录成功)admin登录$ docker login 115.159.227.249Username: adminPassword:Login Succeeded打 tag 并 pushdocker tag ubuntu:15.10 115.159.227.249/library/ubuntu:15.10 //给我的镜像打个 tagdocker push 115.159.227.249/library/ubuntuThe push refers to a repository [115.159.227.249/library/ubuntu]98d59071f692: Pushedaf288f00b8a7: Pushed4b955941a4d0: Pushedf121afdbbd5d: Pushed15.10: digest: sha256:ec89c4a90f45f5e1f48d8379e0504a2881ff706aef0768dc0321b size: 1150上传完毕后,登录Web Harbor,选择项⽬ library,就可以看到我刚 push 的镜像了。同理,你也可以测试下从 Harbor pull 镜像到你的 Docker 中去,这⾥就不继续演⽰了。以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

2023年6月21日发(作者:)

详解基于Harbor搭建Docker私有镜像仓库什么是 Harbor?第⼀次使⽤这个的时候是刚进公司处理的第⼀个任务的时候,发现 Harbor 就是⼀个⽤于存储和分发 Docker 镜像的企业级Registry 服务器。⽹上找到⼀个 Harbor 的架构图:环境准备1、⾃⼰在腾讯云买的服务器(CentOS7.3)2、Docker 版本:17.05.0-ce3、Docker-compose:1.17.14、Harbor:1.1.2安装 Docker因为系统是 CentOS 7.3 ,内核啥的都已经是 3.10,所以不⽤担⼼内核升级的问题,⼀些操作啥的在 7.x 上操作也很⽅便。yum update //系统版本更新vim /etc/.d/ //添加以下内容[dockerrepo]name=Docker Repositorybaseurl=/repo/main/centos/7/enabled=1gpgcheck=1gpgkey=/gpg//下⾯安装 Docker 引擎yum install docker-engine -y//安装docker引擎,此步也可作为更新docker版本的操作:先#systemctl stop docker 停⽌docker服务,再#yum install docker-engine 更新docker版本systemctl enable esystemctl start docker //启动docker守护进程docker info //查看docker运⾏情况docker -v //查看版本信息修改 Docker 配置⽂件 /etc/default/docker 如下:复制代码 代码如下:DOCKER_OPTS="--registry-mirror=" //换成国内的镜像加速源,不然拉取镜像简直龟速,不想在吐槽了使⽤

service docker restart 重启 Docker 服务即可。或者⽤官⽅提供的⽅式:复制代码 代码如下:curl -sSL /daotools/set_ | sh -s [/code]安装 Docker-compose如果是想直接命令安装也⾏,下载指定版本的docker-compose对⼆进制⽂件赋可执⾏权限chmod +x /usr/local/bin/docker-compose测试下docker-compose是否安装成功docker-compose --version出现如下docker-compose version 1.17.1, build 6d101fb但是,这种⽅法简直龟速,幸好还有种⽅法,这种需要通过 Python 的 pip 安装安装 pipwget --no-check-certificate /packages/source/s/setuptools/ -vxf setuptools-1.4.2python2.7 install //因为服务器⾃带 Python 2.7easy_install-2.7 pip安装 docker composepip install docker-composedocker-compose --version //测试安装是否成功安装 Harborwget /vmware/harbor/releases/download/v1.1.2/#离线安装包,也是龟速,把这个下载链接⽤迅雷下载,速度却贼快,嘿嘿,然后再传到服务器上去,整个过程快很多!tar -zxvf 解压缩之后,进⼊⽬录下会看到 ⽂件,该⽂件就是 Harbor 的配置⽂件。## Configuration file of Harbor# hostname设置访问地址,可以使⽤ip、域名,不可以设置为127.0.0.1或localhosthostname = 115.159.227.249 #这⾥我先配置我的服务器IP地址# 访问协议,默认是http,也可以设置https,如果设置https,则nginx ssl需要设置onui_url_protocol = http# mysql数据库root⽤户默认密码root123,实际使⽤时修改下db_password = root123#Maximum number of job workers in job servicemax_job_workers = 3#Determine whether or not to generate certificate for the registry's token.#If the value is on, the prepare script creates new root cert and private key#for generating token to access the registry. If the value is off the default key/cert will be used.#This flag also controls the creation of the notary signer's ize_crt = on#The path of cert and key files for nginx, they are applied only the protocol is set to httpsssl_cert = /data/cert/_cert_key = /data/cert/#The path of secretkey storagesecretkey_path = /data#Admiral's url, comment this attribute, or set its value to NA when Harbor is standaloneadmiral_url = NA#NOTES: The properties between BEGIN INITIAL PROPERTIES and END INITIAL PROPERTIES#only take effect in the first boot, the subsequent changes of these properties#should be performed on web ui#************************BEGIN INITIAL PROPERTIES************************#Email account settings for sending out password resetting emails.#Email server uses the given username and password to authenticate on TLS connections to host and act as identity.#Identity left blank to act as _identity =email_server = il_server_port = 25email_username = sample_admin@il_password = abcemail_from = admin email_ssl = false##The initial password of Harbor admin, only works for the first time when Harbor starts.#It has no effect after the first launch of Harbor.# 启动Harbor后,管理员UI登录的密码,默认是Harbor12345harbor_admin_password = Harbor12345# 认证⽅式,这⾥⽀持多种认证⽅式,如LADP、本次存储、数据库认证。默认是db_auth,mysql数据库认证auth_mode = db_auth#The url for an ldap _url = ldaps://#A user's DN who has the permission to search the LDAP/AD server.#If your LDAP/AD server does not support anonymous search, you should configure this DN and ldap_search_pwd.#ldap_searchdn = uid=searchuser,ou=people,dc=mydomain,dc=com#the password of the ldap_searchdn#ldap_search_pwd = password#The base DN from which to look up a user in LDAP/ADldap_basedn = ou=people,dc=mydomain,dc=com#Search filter for LDAP/AD, make sure the syntax of the filter is correct.#ldap_filter = (objectClass=person)# The attribute used in a search to match a user, it could be uid, cn, email, sAMAccountName or other attributes depending on your LDAP/AD ldap_uid = uid#the scope to search for users, 1-LDAP_SCOPE_BASE, 2-LDAP_SCOPE_ONELEVEL, 3-LDAP_SCOPE_SUBTREEldap_scope = 3#Timeout (in seconds) when connecting to an LDAP Server. The default value (and most reasonable) is 5 _timeout = 5# 是否开启⾃注册self_registration = on# Token有效时间,默认30分钟token_expiration = 30# ⽤户创建项⽬权限控制,默认是everyone(所有⼈),也可以设置为adminonly(只能管理员)project_creation_restriction = everyone#Determine whether the job service should verify the ssl cert when it connects to a remote registry.#Set this flag to off when the remote registry uses a self-signed or untrusted _remote_cert = on#************************END INITIAL PROPERTIES************************启动 harbor,修改完配置⽂件后,在的当前⽬录执⾏./,Harbor服务就会根据当期⽬录下的开始下载依赖的镜像,检测并按照顺序依次启动各个服务。登录 Web Harbor , 输⼊⽤户名 admin,默认密码(或已修改密码)登录系统。我们可以看到系统各个模块如下:项⽬:新增/删除项⽬,查看镜像仓库,给项⽬添加成员、查看操作⽇志、复制项⽬等⽇志:仓库各个镜像create、push、pull等操作⽇志系统管理1. ⽤户管理:新增/删除⽤户、设置管理员等2. 复制管理:新增/删除从库⽬标、新建/删除/启停复制规则等3. 配置管理:认证模式、复制、邮箱设置、系统设置等其他设置1. ⽤户设置:修改⽤户名、邮箱、名称信息2. 修改密码:修改⽤户密码注意:⾮系统管理员⽤户登录,只能看到有权限的项⽬和⽇志,其他模块不可见。我们要尝试下能不能把⾃⼰ Docker ⾥⾯的镜像 push 到 Harbor 的 library ⾥来(默认这个 library 项⽬是公开的,所有⼈都可以有读的权限,都不需要 docker login 进来,就可以拉取⾥⾯的镜像)。注意:为了后⾯留坑,我这⾥先 在⾃⼰的 e 中添加仓库:(这是个坑,建议你先按照我说的做,不然下⾯可能会⼀直登录不上)vim /usr/lib/systemd/system/e#⾥⾯的这⾏修改为:(其实就是添加 --insecure-registry 115.159.227.249 )ExecStart=/usr/bin/dockerd --insecure-registry 115.159.227.249添加完了后重新启动 docker:systemctl daemon-reload && systemctl enable docker && systemctl start docker启动 docker 服务:service docker start登录:(为了测试下能否登录成功)admin登录$ docker login 115.159.227.249Username: adminPassword:Login Succeeded打 tag 并 pushdocker tag ubuntu:15.10 115.159.227.249/library/ubuntu:15.10 //给我的镜像打个 tagdocker push 115.159.227.249/library/ubuntuThe push refers to a repository [115.159.227.249/library/ubuntu]98d59071f692: Pushedaf288f00b8a7: Pushed4b955941a4d0: Pushedf121afdbbd5d: Pushed15.10: digest: sha256:ec89c4a90f45f5e1f48d8379e0504a2881ff706aef0768dc0321b size: 1150上传完毕后,登录Web Harbor,选择项⽬ library,就可以看到我刚 push 的镜像了。同理,你也可以测试下从 Harbor pull 镜像到你的 Docker 中去,这⾥就不继续演⽰了。以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。