需求
在局域网内,在一台机器上搭建镜像仓库,其他节点能够通过内网镜像仓库pull、push等
实操步骤
- 仓库节点IP:192.168.83.141
- 仓库节点上创建镜像存放目录:
mkdir -p /data/registry
- 设置仓库节点上Docker镜像加速:Aliyun
- pull registry:
sudo docker pull registry
[liu@localhost docker]$ sudo docker pull registry
[sudo] liu 的密码:
Using default tag: latest
latest: Pulling from library/registry
79e9f2f55bf5: Pull complete
0d96da54f60b: Pull complete
5b27040df4a2: Pull complete
e2ead8259a04: Pull complete
3790aef225b9: Pull complete
Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
- 运行registry镜像:
sudo docker run -d -v /data/registry:/var/lib/registry -p 5000:5000 --restart=always b8604a3fe854(registry镜像ID)
,查看容器:
[liu@localhost registry]$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
609cbf29e5c9 b8604a3fe854 "/entrypoint.sh /etc…" 6 seconds ago Up 5 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp jovial_pare
- 修改HTTP设置:
vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://XXXXXXX.mirror.aliyuncs.com"],
"insecure-registries":["http://192.168.83.141:5000"]
}
-
重启Docker:
sudo systemctl daemon-reload
、sudo systemctl restart docker
-
客户机上也修改HTTP设置(我这里是Windows Docker Desktop)
使用
- 客户机上先给镜像打标签:
docker tag gisliuliang/test-demo:v0.1 192.168.83.141:5000/test-demo:v0.1
- 客户机上push:
docker push 192.168.83.141:5000/test-demo:v0.1
# docker push 192.168.83.141:5000/test-demo:v0.1
The push refers to repository [192.168.83.141:5000/test-demo]
c7e172568a34: Pushed
419df8b60032: Pushed
0e835d02c1b5: Pushed
5ee3266a70bd: Pushed
3f87f0a06073: Pushed
1c9c1e42aafa: Pushed
8d3ac3489996: Pushed
v0.1: digest: sha256:330f361a99a1bfd589483d35f84cb12f2ab3e60f1441aa32eddececdda989c16 size: 1775
- 查看API:
http://192.168.83.141:5000/v2/_catalog