Preparing the Environment
Environment: two centos7 virtual machine
A virtual machine: 192.168.249.132 as a private warehouse
Virtual machine two: 192.168.249.133 user development machine
A mounting Docker (VM I, II)
Two hosts need to be installed, docker reference mounting step
https://blog.51cto.com/14129044/2425605
Second, the installation docker-compose (a virtual machine)
curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version
Third, the installation Harbor (a virtual machine)
1, obtain the installation package harbor
wget https://storage.googleapis.com/harbor-releases/release-1.8.0/harbor-online-installer-v1.8.1.tgz
tar xvf harbor-online-installer-v1.8.1.tgz
2, harbor.yml directory under the configuration harbor
vim harbor.yml
The hostname to the local IP, other parameters may be default values; port is the port number of the harbor, harbor_admin_password password for the user admin
3, start the harbor
./install.sh
4, the browser enter 192.168.249.132 following interface pops up, use the admin account login
5, the new project (warehouse)
新建一个名称为abc的私有仓库,设置不公开
注意:当项目设为公开后,任何人都有此项目下镜像的读权限。命令行用户不需要“docker login”就可以拉取此项目下的镜像。
四、使用镜像仓库(虚机二)
1、在用户机登录私有仓库
docker login 192.168.249.132
若提示"Error response from daemon: Get https://192.168.249.132/v2/: dial tcp 192.168.249.132:443: connect: connection refused"
docker1.3.2版本开始默认docker registry使用的是https,我们设置Harbor默认http方式,所以当执行用docker login、pull、push等命令操作非https的docker regsitry的时就会报错。
解决,在发起登录的客户端主机上的文件(如没有则创建)/etc/docker/daemon.json中添加如下参数:
{
"insecure-registries": ["192.168.249.132"]
}
重启docker:systemctl restart docker.service
再次登录,显示成功
2、上传镜像到仓库
查看本机当前存在nginx:latest镜像
先打tag,然后再push上传
docker tag nginx:latest 192.168.249.132/abc/nginx:v1
docker push 192.168.249.132/abc/nginx:v1
3、镜像下载
用户机上先将刚刚上传的192.168.249.132/abc/nginx:v1 镜像删除,使用docke image ls命令查看保证本地已无该镜像
再使用pull命令去私有镜像仓库下载,可看到已下载成功
docker pull 192.168.249.132/abc/nginx:v1