Docker--(仓库创建和管理)

镜像仓库的概念

docker仓库是我们构建的用来存镜像的地方。官方给我们提供了公有仓库和私有仓库。Docker官方提供的工具docker-registry可以用于构建私有的镜像仓库。这是docker公司将自己的仓库开源了,方便大家使用。企业用户一般使用私有仓库,当前私有仓库用的最多的还是vmware公司提供的私有仓库harbor。

1.镜像仓库的构建

(一).基于docker的私有仓库搭建(默认支持https协议)
1.网络规划
docker-serer端(服务端):192.168.66.12
docker-agent端(客户端):192.168.66.11

2.服务搭建(以HTTP方式上传文件)
(1).下载并启动docker-registry
[root@localhost ~]# docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always registry
Unable to find image ‘registry:latest’ locally
latest: Pulling from library/registry
cbdbe7a5bc2a: Pull complete
47112e65547d: Pull complete
46bcb632e506: Pull complete
c1cc712bcecd: Pull complete
3db6272dcbfa: Pull complete
Digest: sha256:8be26f81ffea54106bae012c6f349df70f4d5e7e2ec01b143c46e2c03b9e551d
Status: Downloaded newer image for registry:latest
0f251e18e83b9758a5ea389d9fd28e23127affec4aee44700a79b32853563863

(二).将自己要上传的镜像打上标签
[root@localhost ~]# docker tag nginx:v3 nginx:t1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx t1 093db9fd201c 18 hours ago 133MB

(三).设置为http方式上传镜像并服务器端测试(此时我们上传文件会被拒绝,因为docker仓库默认上传是基于https的,因为我们这里暂时没有ssl认证的证书和key,所以我们需要修改一下,改为http方式。)一定要记得修改镜像名,否则会报错。

服务器端测试
[root@localhost ~]# vim /etc/docker/daemon.json
{“registry-mirrors”: [“http://f1361db2.m.daocloud.io”] #镜像加速器
“insecure-registries”: [“192.168.66.12:5000”]} # 以http方式上传到指定的仓库
[root@server1 opt]# systemctl daemon-reload
[root@server1 opt]# systemctl restart docker
#重新加载模块使配置生效
[root@localhost ~]# docker tag 10.10.34.14:5000/centos:01 192.168.66.12:5000/centos
#记得修改镜像名为:IP:端口/镜像名
[root@localhost ~]# docker push 192.168.66.12:5000/centos
The push refers to repository [192.168.66.12:5000/centos]
291f6e44771a: Pushing 56.14MB/215.1MB

客户端测试(配置如上)

2.基于vmware公司harbor私有仓库的搭建

1.安装底层要求
(1)python应该是2.7或更高版本
(2)docker引擎为1.10或更高版本
(3)docker compose需要为1.6.0或更高版本
(4)安装docker环境和docker-compose环境
curl -L “https://github.com/docker/compose/releases/download/1.23.2/docker-compose-( u n a m e − s ) − (uname -s)-(uname−s)−(uname -m)” -o /usr/local/bin/docker-compose

2.harbor文件说明及安装步骤:harbor官方https://github.com/vmware/harbor/releases
#文件说明
(1)proxy:由nginx服务器构成的反向代理
(2)registry:由docker官方的开源registry镜像构成的容器实例
(3)UI:即架构中的core services,构成此容器的代码是harbor项目的主体
(4)MySQL:由官方MySQL镜像构成的数据库容器
(5)log:运行着rsyslogd的容器,通过log-driver的形式收集其他容器的日志

安装步骤
(1)[root@localhost opt]# tar -zxvf harbor-offline-installer-v1.2.0.tgz

(2)https访问密钥及认证
mkdir /opt/harbor/certs -p
cd /opt/harbor/certs
openssl genrsa -des3 -out server.key 2048 #创建私钥
openssl req -new -key server.key -out server.csr #创建证书请求
cp server.key server.key.org #密钥备份
openssl rsa -in server.key.org -out server.key #密钥解密,让证书变为非密码状态
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt #签发证书
chmod 777 /opt/harbor/certs
#给密钥目录权限

(3)cd ~
cd harbor
修改配置文件:vim harbor.cfg

主机名改成本服务器的ip
hostname = 192.168.66.12

访问的协议https
ui_url_protocol = https

由于前一步我们自己生成了证书,所以该值改为off
customize_crt = off

ssl证书的路径
ssl_cert = /opt/harbor/certs/server.cert

ssl密钥的路径
ssl_cert_key = /opt/harbor/certs/server.key
secretkey_path = /opt/harbor

设置ui系统的admin账号的密码,默认为Harbor12345
harbor_admin_password = Harbor12345

(4)导入镜像
cd /harbor
./install.sh

(5)访问测试 https://reg.yourdomain.com的管理员门户(将reg.yourdomain.com更改为您的主机名harbor.cfg)请注意,默认管理员用户名/密码为admin /Harbor12345

##Harbor安装报错502 Bad Gateway
https://www.opskb.com/ITHelp/672.html

查看/var/log/harbor/adminserver.log 日志有以下报错
Dec 25 02:39:18 172.18.0.1 adminserver[2641]: 2020-8-25T07:39:18Z [INFO] initializing system configurations…
[driver_json.go:46]: path of configuration file: /etc/adminserver/config/config.json
Dec 25 02:39:18 172.18.0.1 adminserver[2641]: 2017-12-25T07:39:18Z [INFO] the path of key used by key provider: /etc/adminserver/key

设置下权限,设置目录下面secretkey文件的所属者
chown 10000:10000 /mycre/secretkey
然后执行
docker-compose down
docker-compose up -d

还原设置secretkey_path的路径为/data
切换harbor的安装目录执行以下操作
[root@localhost harbor]#docker-compose down
[root@localhost harbor]#rm -rf /data/secretkey
[root@localhost harbor]#./prepare
[root@localhost harbor]#docker-compose up –d

(6)上传镜像测试
a、指定仓库镜像地址:vim/etc/docker/daemon.json
{“insecure-registries”: [“serverip”] }
systemctl restart docker
b、下载测试镜像 docker pull hello-world
c、给镜像打上标签: docker tag hello-world serverip/hello-world:latest
d、docker login serverip

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值