创建两个目录
/var/lib/docker
,windows 为C:\ProgramData\docker
mkdir /data/docker
mkdir /data/registry
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
sudo yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
配置
cat <<EOF> /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"data-root": "/data/docker",
"live-restore": true,
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "5"
}
}
EOF
启动
sudo systemctl start docker && systemctl enable docker && systemctl status docker
验证
$ ls /data/docker/
buildkit containers engine-id image network overlay2 plugins runtimes swarm tmp volumes
拉取镜像
docker pull registry:2.8.3
创建镜像仓库
docker run -tid --restart=always --name registry -p 80:5000 -v /data/registry:/var/lib/registry registry:2.8.3
检查状态
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
238a044893a5 registry:2.8.3 "/entrypoint.sh /etc…" 5 seconds ago Up 4 seconds 0.0.0.0:80->5000/tcp, :::80->5000/tcp registry
配置域名解析
echo "192.168.10.22 registry01.ghostwritten.com" >> /etc/hosts
修改配置
$ cat /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"insecure-registries": ["registry01.ghostwritten.com"], #添加
"data-root": "/data/docker",
"live-restore": true,
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "5"
}
}
$ systemctl restart docker
检查仓库
$ curl 192.168.10.22/v2/_catalog
{"repositories":[]}
推送镜像
$ docker tag registry:2.8.3 registry01.ghostwritten.com/library/registry:2.8.3
$ docker push registry01.ghostwritten.com/library/registry:2.8.3
The push refers to repository [registry01.ghostwritten.com/library/registry]
ab4798a34c77: Layer already exists
0b261c932361: Layer already exists
d95d36f1fde7: Layer already exists
b4fcd5c55862: Layer already exists
cc2447e1835a: Layer already exists
2.8.3: digest: sha256:386cdae4ba70c368b780a6e54251a14d300281a3d147a18ef08ae6fb079d150c size: 1363
拉取镜像镜像
登陆另一台节点,重复上面安装docker 、配置docker、配置域名解析,即可拉取镜像
docker pull registry01.ghostwritten.com/library/registry:2.8.3
参考: