1.系统环境:

# uname -a

Linux Rocky 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Tue Dec 21 19:02:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

# lsb_release -a

Distributor ID: Rocky

Description:    Rocky Linux release 8.5 (Green Obsidian)

Release:        8.5

Codename:       GreenObsidian

# docker version


Version: 20.10.12

2.创建私有镜像库:

# ip addr

192.168.225.136    // 服务器端IP,所有IP配置使用宿主机IP,不使用容器IP

# docker pull registry       

# docker images

REPOSITORY                        TAG             IMAGE ID       CREATED         SIZE

registry                          latest          2e200967d166   4 weeks ago     24.2MB

# docker run -d -p 5000:5000 --restart always --name registry registry:latest   

3.客户端环境配置:

# ip addr

192.168.225.130

# telnet 192.168.225.136 5000    // 显示如下信息表示可以访问服务器端5000端口

Trying 192.168.225.136...

Connected to 192.168.225.136.

Escape character is '^]'.

# systemctl stop docker

# cd /etc/docker

# vim daemon.json     // 该文件不存在需要手动创建

添加如下内容,保存退出

{ "insecure-registries":["192.168.225.136:5000"] }

# cd /usr/lib/systemd/system

# vim docker.service       // 建议编辑前备份该文件

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock  //在该行下面添加下面一行

EnvironmentFile=-/etc/docker/daemon.json

# systemctl daemon-reload

# systemctl start docker

4.客户端上传镜像:

(1).上传dockerfile生成镜像:

         # build -t 192.168.225.136:5000/nginx-server ./

         # docker push 192.168.225.136:5000/nginx-server

(2).上传本地镜像

         # docker tag nginx:latest 192.168.225.136:5000/nginx-server

         # docker push 192.168.225.136:5000/nginx-server

5.查看私有镜像服务器有哪些镜像:

# curl http://192.168.225.136:5000/v2/_catalog

{"repositories":["nginx-server"]}

6.从镜像服务器拉去镜像:

  # docker pull 192.168.225.136:5000/nginx-server