docker仓库创建:官方仓库和第三方仓库
一、配置私有镜像仓库(官方)
1)服务器端配置
[[email protected] /]# docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always registry 运行仓库容器
[[email protected] /]# vim /etc/docker/daemon.json 编辑第二个主配置文件
{
“insecure-registries”: [“192.168.200.250:5000”]
}
2)客户端配置
客户端上传标准:
仓库地址/username(认证过的)/imagename:tag
[[email protected] /]# vim /usr/lib/systemd/system/docker.service 编辑docker服务文件
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.200.250:5000 添加
[[email protected] /]# docker tag hub.c.163.com/public/centos:6.7-tools 192.168.200.250:5000/centos:6.7-tools 修改镜像名字
[[email protected] /]# docker push 192.168.200.250:5000/centos:6.7-tools 上传镜像
[[email protected] /]# curl -XGET http://192.168.200.250:5000/v2/_catalog 查看上传的镜像
[[email protected] /]# docker pull 192.168.200.250:5000/centos:6.7-tools 下载镜像
二、第三方仓库
1、创建https证书以及配置相关目录权限(若生产环境可申请)
[[email protected] ~]# openssl genrsa -des3 -out server.key 2048 创建证书
Enter pass phrase for server.key: 输入密码
Verifying - Enter pass phrase for server.key: 确认密码
[[email protected] ~]# openssl req -new -key server.key -out server.csr 证书请求
Enter pass phrase for server.key: 证书密码
Country Name (2 letter code) [XX]:CN 输入国家
State or Province Name (full name) []:BJ 省
Locality Name (eg, city) [Default City]:BJ 市
Organization Name (eg, company) [Default Company Ltd]:iso 组织名称
Organizational Unit Name (eg, section) []:iso 组织单位名称
Common Name (eg, your name or your server’s hostname) []: hub.iso.com域名
Email Address []: [email protected]邮箱
A challenge password []:
An optional company name []:
[[email protected] ~]# cp server.key server.key.org
[[email protected] ~]# openssl rsa -in server.key.org -out server.key 退证书,需使用**使用
[[email protected] ~]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt 创建证书
[[email protected] ~]# mkdir -p /data/cert 创建目录,目录是特定的,在hardor中可见
[[email protected] ~]# mv ./server.* /data/cert/ 将证书转移到/data/cert
2、修改habor.cfg文件
[[email protected] harbor]# vim harbor.cfg
hostname = hub.iso.com 域名
ui_url_protocol = https 使用的网络协议
harbor_admin_password = [email protected] 管理员密码
[[email protected] harbor]# chmod +x ./install.sh 授予执行权限
[[email protected] harbor]# chmod 755 ./prepare 授予文件权限
[[email protected] harbor]# ./install.sh 安装harbor
3、配置服务器端
[[email protected] /]# vim /etc/docker/daemon.json
{
“insecure-registries”: [“hub.iso.com”]
}
[[email protected] /]# systemctl restart docker.service
4、配置客户端
[[email protected] /]# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --registry-mirror=https://uqih1i5y.mirror.aliyuncs.com --insecure-registry hub.iso.com
[[email protected] /]# systemctl daemon-reload
[[email protected] /]# systemctl restart docker
5、客户端测试上传(个人私库上传)
[[email protected] /]# docker tag hub.c.163.com/public/centos:6.7-tools hub.iso.com/xitong/centos:6.7-tools 修改镜像名字
[[email protected] /]# docker login hub.iso.com 登录到个人私库
[[email protected] /]# docker push hub.iso.com/xitong/centos:6.7-tools 上传