Docker仓库

1 官方仓库构建

1.1 仓库服务器的配置

docker run -d -v /var/docker/registry:/var/lib/registry -p 5000:5000 --restart=always registry
vim /etc/docker/daemon.json
{
	"registry-mirrors": ["https://du3ia00u.mirror.aliyuncs.com"],
	"insecure-registries": ["192.168.179.100:5000"]
}
systemctl daemon-reload
systemctl restart docker

192.168.179.100是仓库服务器的地址。

  • 验证是否安装成功:
http://192.168.179.100:5000/v2/

验证是否安装成功

  • 从Docker Hub上拉取镜像:
docker pull hello-world
  • 将拉取到本地的镜像改为ip地址:端口号/用户名/镜像名称:标签:
docker tag hello-world:latest 192.168.179.100:5000/hello-world:v1.0
  • 推送镜像到本地仓库:
docker push 192.168.179.100:5000/hello-world:v1.0

推送成功

1.2 客户端设置

vim /etc/docker/daemon.json
{
	"registry-mirrors": ["https://du3ia00u.mirror.aliyuncs.com"],
	"insecure-registries": ["192.168.179.100:5000"]
}
systemctl daemon-reload
systemctl restart docker
docker pull 192.168.179.100:5000/hello-world:v1.0

2 Harbor仓库构建

2.1 安装底层需求

  • Python应该为2.7或更高版本。
  • Docker引擎应该为1.10或更高版本。
  • Docker Compose应该为1.6.0或更高版本。

2.2 Harbor的安装

2.2.1 解压压缩包

wget https://github.com/goharbor/harbor/releases/download/v1.2.0/harbor-offline-installer-v1.2.0.tgz
tar -zxvf harbor-offline-installer-v1.2.0.tgz

解压文件

2.2.2 移动harbor到/usr/local目录下

mv harbor /usr/local

移动harbor文件夹

2.2.3 创建https证书以及配置相关目录权限

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 

mkdir -pv /data/cert

创建目录

chmod -R 777 /data/cert 

mv server.* /data/cert/

将证书移动到指定的目录

2.2.4 修改harbor.cfg配置文件

cd /usr/local/harbor
vim harbor.cfg

hostname = hub.sunxiaping.com
ui_url_protocol = https

修改harbor.cfg配置文件

2.2.5 安装

  • 在/usr/local/harbor目录下执行如下的命令:
./install.sh

harbor安装成功

2.3 Harbor的访问测试

  • 在浏览器中输入https://192.168.64.100/harbor/sign-in,并输入admin/Harbor12345进行登录。

Harbor访问测试

2.3 Harbor指定镜像仓库的地址

vim /etc/docker/daemon.json
{
	"registry-mirrors": ["https://du3ia00u.mirror.aliyuncs.com"],
	"insecure-registries": ["192.168.64.100","hub.sunxiaping.com"]
}
systemctl daemon-reload
systemctl restart docker
vim /etc/hosts

192.168.64.100 hub.sunxiaping.com

2.4 Harbor下载测试镜像

docker pull hello-world

2.5 Harbor给镜像重新打上标签

docker tag hello-world:latest hub.sunxiaping.com/sy/hello-world:v1.0

2.6 Harbor登录

docker login 192.168.64.100

或

docker login hub.sunxiaping.com

2.7 Harbor推送镜像

docker push hub.sunxiaping.com/sy/hello-world:v1.0

Harbor推送私有镜像成功

2.8 其他Docker客户端下载镜像

2.8.1 指定镜像仓库地址

vim /etc/docker/daemon.json
{
	"registry-mirrors": ["https://du3ia00u.mirror.aliyuncs.com"],
	"insecure-registries": ["192.168.64.100","hub.sunxiaping.com"]
}
systemctl daemon-reload
systemctl restart docker
vim /etc/hosts

192.168.64.100 hub.sunxiaping.com

2.8.2 登录

docker login 192.168.64.100
或
docker login hub.sunxiaping.com

2.8.3 下载镜像

docker pull hub.sunxiaping.com/sy/hello-world:v1.0
原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/13660348.html