总结的坑:
a. 关注 daemon.JSON 的书写格式. 一句话可以错好几个点.
b.tag 要清楚的表示 registry 服务器的信息, 才能 push 上传成功. 不是可有可无的信息.
c.tag 中有版本号要清楚的写上. 系统自动补全的是用 latest.
####################################################################
搭建过程:
前提: 通过 docker pull registry 下载了 registry
1. 新建的 / etc/docker/daemon.JSON
- [[email protected] docker]# cat daemon.JSON
- {
- "insecure-registries": ["172.17.0.1:5000"]
- }
下面这种报错, 是因为新建的 / etc/docker/daemon.JSON 文件还没有成功.
- [[email protected] ~]# docker push 172.17.0.1:5000/hello-world
- The push refers to repository [172.17.0.1:5000/hello-world]
- Get https://172.17.0.1:5000/v2/ : http: server gave HTTP response to HTTPS client
容易出错的 4 个地方:
a. 错误的写成 insecure-registry.
b. 错误的写成 http://172.17.0.1:5000/
c. 错误的用了容器的 IP 172.17.0.2
d. 忘记重启 docker 服务
#########################################################################
2. 本地是否建立成功 registry, 可以通过 docker info 查看
- [[email protected] docker]# docker info | grep -i -A 3 regis
- Registry: https://index.docker.io/v1/
- Labels:
- Experimental: false
- Insecure Registries:
- 172.17.0.1:5000
- 127.0.0.0/8
- Live Restore Enabled: false
- ##########################################################################
3. 启动本地 registry 容器, push 上传 image 到本地 registry 容器
- mkdir -p /data/registry
- ##host 上创建目录 volume 给容器做存储
- docker run -d -p 5000:5000 -v /data/registry:/var/lib/registry --name local_registry registry
- ## 启动容器, 对外用 5000 端口, 第一个 5000 是 host 的端口, 第二个 5000 是容器端口
- [[email protected] docker]# docker ps | grep -i local_registry
- b4c6b769aabc registry "/entrypoint.sh /etc..." About an hour ago Up 30 minutes 0.0.0.0:5000->5000/tcp local_registry
- ## 检查 registry 容器是否启动
- [[email protected] ~]# docker tag hello-world 172.17.0.1:5000/hello-world:v1
- [[email protected] ~]# docker push 172.17.0.1:5000/hello-world:v1
- The push refers to repository [172.17.0.1:5000/hello-world]
- af0b15c8625b: Pushed
- v1: digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a size: 524
- [[email protected] ~]#
- ## 注意: docker tag hello-world 172.17.0.1:5000/hello-world:v1 一定要打上正确的 tag, 也就是 tag 一定要清楚表示清楚是哪个 registry.
不然, docker 不知道是要将 image 上传到哪个 registry 服务器. 也就是说 tag 包含了 registry 服务器的信息, 不是一个可有可无的东西.
##########################################################################
4. 删除 host 上有的 images. 测试从容器 pull 下来 image.
注意: 删除或者上传是如果有版本号不是 latest, 需要附加上. 系统默认是自动补充 latest, 这样执行命令后反馈找不到
- [[email protected] docker]# docker rmi 172.17.0.1:5000/hello-world
- Error: No such image: 172.17.0.1:5000/hello-world
- [[email protected] docker]# docker rmi 172.17.0.1:5000/hello-world:v1
- Untagged: 172.17.0.1:5000/hello-world:v1
- Untagged: 172.17.0.1:5000/[email protected]:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a
- [[email protected] docker]#
- [[email protected] docker]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- mariadb latest 3a2ef06682ac 9 hours ago 356MB
- WordPress latest a541a1a59631 2 days ago 447MB
- busybox latest e4db68de4ff2 2 weeks ago 1.22MB
- registry.aliyuncs.com/google_containers/kube-proxy v1.14.0 5cd54e388aba 3 months ago 82.1MB
- registry.cn-beijing.aliyuncs.com/imcto/flannel v0.11.0-amd64 03ad33ab3dd7 3 months ago 52.6MB
- registry latest f32a97de94e1 3 months ago 25.8MB
- [[email protected] docker]#
- [[email protected] docker]# docker pull 172.17.0.1:5000/hello-world
- Using default tag: latest
- Error response from daemon: manifest for 172.17.0.1:5000/hello-world:latest not found
- [[email protected] docker]# docker pull 172.17.0.1:5000/hello-world:v1
- v1: Pulling from hello-world
- 1b930d010525: Pull complete
- Digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a
- Status: Downloaded newer image for 172.17.0.1:5000/hello-world:v1
- [[email protected] docker]#
- [[email protected] docker]# docker images
- REPOSITORY TAG IMAGE ID CREATED SIZE
- mariadb latest 3a2ef06682ac 9 hours ago 356MB
- WordPress latest a541a1a59631 2 days ago 447MB
- busybox latest e4db68de4ff2 2 weeks ago 1.22MB
- registry.cn-beijing.aliyuncs.com/imcto/flannel v0.11.0-amd64 03ad33ab3dd7 3 months ago 52.6MB
- registry latest f32a97de94e1 3 months ago 25.8MB
- 172.17.0.1:5000/hello-world v1 fce289e99eb9 6 months ago 1.84kB
- [[email protected] docker]#
来源: http://www.bubuko.com/infodetail-3113558.html