文章目录
一:搭建一个简易的本地私有仓库
1.1 下载一个本地仓库的容器
[root@gsy ~]# docker pull registry
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@gsy ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd cetnos 38d2d5159957 11 hours ago 434MB
registry latest 708bc6af7e5e 2 months ago 25.8MB
centos 7 5e35e350aded 5 months ago 203MB
1.2 编辑守护进程文件,添加本地仓库IP,然后重启docker
[root@gsy ~]# vim /etc/docker/daemon.json
{
#下面一行为新添加内容·,指定本地IP和端口
"insecure-registries": ["192.168.247.134:5000"],
"registry-mirrors": ["https://fk2yrsh1.mirror.aliyuncs.com"]
}
[root@gsy ~]# systemctl restart docker
1.3 运行容器registry仓库
[root@gsy ~]# docker create -it registry /bin/bash
c510b459f332514c06a8137b5563fa2a588e8df8e4a290c88816216befe6d45d
[root@gsy ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c510b459f332 registry "/entrypoint.sh /bin…" 5 seconds ago Created heuristic_bhaskara
[root@gsy ~]# docker start c510b459f332
c510b459f332
[root@gsy ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c510b459f332 registry "/entrypoint.sh /bin…" 48 seconds ago Exited (127) 1 second ago
1.4 运行一个镜像
-d 指定守护进程
-p 指定宿主机端口:容器端口映射
-v 指定宿主机目录:容器目录之间挂载,若是当前没有目录会自动创建
[root@gsy ~]# docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry
76b39f97068d330f4fa916c237e797e78c0e2b909a185698f8d15378c82c2e13
[root@gsy ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c8322c689584 registry "/entrypoint.sh /etc…" 19 seconds ago Up 18 seconds 0.0.0.0:5000->5000/tcp dazzling_wu
c510b459f332 registry "/entrypoint.sh /bin…" 2 minutes ago Exited (127) About a minute ago heuristic_bhaskara
1.5 下载nginx镜像测试,并更改镜像标记为192.168.247.134:nginx
[root@gsy ~]# docker pull nginx
[root@gsy ~]# docker tag nginx:latest 192.168.247.134:5000/nginx
[root@gsy ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd cetnos 38d2d5159957 11 hours ago 434MB
192.168.247.134:5000/nginx latest e791337790a6 2 days ago 127MB
nginx latest e791337790a6 2 days ago 127MB
registry latest 708bc6af7e5e 2 months ago 25.8MB
centos 7 5e35e350aded 5 months ago 203MB
1.6 上传至私有仓库
[root@gsy ~]# docker push 192.168.247.134:5000/nginx
The push refers to repository [192.168.247.134:5000/nginx]
be91fceb796e: Pushed
919b6770519b: Pushed
b60e5c3bcef2: Pushed
latest: digest: sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee size: 948
[root@gsy ~]#
1.7 查看挂载点
[root@gsy ~]# ls -lh /
total 36K
drwxr-xr-x. 4 root root 38 Apr 20 10:09 data
[root@gsy ~]# ls -lh /data/registry/
total 0
[root@gsy ~]#
1.8 查看私有仓库内的镜像
[root@gsy ~]# curl -XGET http://192.168.247.134:5000/v2/_catalog
{"repositories":["nginx"]}
1.9 删除现有镜像文件,然后测试从本地仓库拉取
[root@gsy ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd cetnos 38d2d5159957 12 hours ago 434MB
192.168.247.134:5000/nginx latest e791337790a6 2 days ago 127MB
nginx latest e791337790a6 2 days ago 127MB
registry latest 708bc6af7e5e 2 months ago 25.8MB
centos 7 5e35e350aded 5 months ago 203MB
[root@gsy ~]# docker rmi 192.168.247.134:5000/nginx
Untagged: 192.168.247.134:5000/nginx:latest
Untagged: 192.168.247.134:5000/nginx@sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee
[root@gsy ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd cetnos 38d2d5159957 12 hours ago 434MB
nginx latest e791337790a6 2 days ago 127MB
registry latest 708bc6af7e5e 2 months ago 25.8MB
centos 7 5e35e350aded 5 months ago 203MB
[root@gsy ~]# docker pull 192.168.247.134:5000/nginx
Using default tag: latest
latest: Pulling from nginx
Digest: sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee
Status: Downloaded newer image for 192.168.247.134:5000/nginx:latest
192.168.247.134:5000/nginx:latest
[root@gsy ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd cetnos 38d2d5159957 12 hours ago 434MB
192.168.247.134:5000/nginx latest e791337790a6 2 days ago 127MB
nginx latest e791337790a6 2 days ago 127MB
registry latest 708bc6af7e5e 2 months ago 25.8MB
centos 7 5e35e350aded 5 months ago 203MB
[]()
二:总结:私有仓库设置步骤
1.下载registry镜像 字符终端
2.生成registry容器,开放5000端口,并映射出去
3.客户端设置daemon.json文件 指定私有仓库位置
4.将要上传的镜像打标签 仓库IP:端口/镜像名
5.上传镜像 docker push 仓库IP:端口/镜像名
6.下载镜像 docker pull 仓库IP:端口/镜像名
7.docker images 查看