Registry
用docker容器运行registry私有仓库
下载registry镜像:
[root@localhost ~]# docker pull registry:2 //2版本是使用go语言编写的,而registry是使用python写的
//运行私有仓库:
[root@localhost ~]# docker run -itd --name registry --restart=always -p 5000:5000 -v /registry:/var/lib/registry registry:2
-p:端口映射(宿主机端口:容器暴露的端口)
-v:挂载目录(宿主机的目录:容器内的目录)
镜像重命名:
[root@localhost ~]# docker tag test-web:latest 192.168.1.70:5000/test
上传镜像到私有仓库:
[root@localhost ~]# vim /usr/lib/systemd/system/docker.service
修改:指定私有仓库地址
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.1.70:5000
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# docker push 192.168.1.70:5000/test:latest
这里注意,既然是私有仓库,肯定是要考虑多台DockerHost共用的情况,如果有其他的DockerHost想要使用私有仓库,仅需要修改docker的配置文件,指定私有仓库的IP和端口即可。当然别忘了,更改过配置文件之后,daemon-reload ,restart docker服务
企业级私有仓库镜像Harbor
下载一个docker-compse工具
//从GitHub上下载方法:
[root@docker01 ~]# curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
[root@docker01 ~]# chmod +x /usr/local/bin/docker-compose
[root@docker01 ~]# tar zxf docker-compose.tar.gz -C /usr/local/bin
[root@docker01 ~]# chmod +x /usr/local/bin/docker-compose
//下载依赖包
[root@docker01 ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
//导入harbo离线安装包,并解压到/usr/local/下
[root@docker01 ~]# tar zxf harbor-offline-installer-v1.7.4.tgz -C /usr/local/
//安装harbor
[root@docker01 ~]# cd /usr/local/harbor/
[root@docker01 harbor]# vim harbor.cfg
hostname = 192.168.1.70
[root@docker01 harbor]# ./install.sh
//浏览器访问:192.168.1.70
用户名:admin
密码:Harbor12345
//修改docker配置文件,连接Harbor私有仓库
[root@docker01 ~]# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.1.70
[root@docker01 ~]# systemctl daemon-reload
[root@docker01 ~]# systemctl restart docker
//创建私有仓库
//登录仓库上传镜像
[root@docker01 harbor]# docker login -u admin -p Harbor12345 192.168.1.70
[root@docker01 harbor]# docker tag centos:7 192.168.1.70/bdqn/centos:7
[root@docker01 harbor]# docker push 192.168.1.70/bdqn/centos:7
//从私有仓库下载镜像
[root@docker03 ~]# docker pull 192.168.1.70/bdqn/centos:7