前言

系统环境:Centos7、jdk1.8

docker私服:可以把项目通过dockerfile文件build成docker镜像,供其他环境拉取。部署在本地,私有化。

安装

dockerHUB私服

1. 搭建registry

 #拉取registry镜像
[root@localhost home]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
c87736221ed0: Pull complete
1cc8e0bb44df: Pull complete
54d33bcb37f5: Pull complete
e8afc091c171: Pull complete
b4541f6d3db6: Pull complete
Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146
Status: Downloaded newer image for registry:latest #查看镜像
[root@localhost home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest f32a97de94e1 6 months ago 25.8MB #启动容器
[root@localhost home]# docker run -d -v /data/registry:/var/lib/registry -p 5000:5000 --restart=always --name qdockerhub registry:latest
67b0ac40561688b8bb874fa9674e44eb069cc6ee443127ba80b140ea51947af7 #测试/v2/_catalog接口
[root@localhost home]# curl http://127.0.0.1:5000/v2/_catalog
{"repositories":[]}
[root@localhost home]#

2. 提交镜像

 #拉取tomcat测试提交
[root@localhost home]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
092586df9206: Pull complete
ef599477fae0: Pull complete
4530c6472b5d: Pull complete
d34d61487075: Pull complete
272f46008219: Pull complete
12ff6ccfe7a6: Pull complete
f26b99e1adb1: Pull complete
21bec9c8ea28: Pull complete
e2f6023231f2: Pull complete
c47eb491a5e3: Pull complete
Digest: sha256:74e52cc6d27dacb079b273c129d6bf32df6ba328d6508b81ef65f41675ae9570
Status: Downloaded newer image for tomcat:latest #查看镜像
[root@localhost home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest 365b0a528e2e 4 days ago 506MB
registry latest f32a97de94e1 6 months ago 25.8MB #给镜像重命名,ip:端口/镜像名称
[root@localhost home]# docker tag tomcat:latest 127.0.0.1:5000/testtomcat #再次查看镜像
[root@localhost home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
127.0.0.1:5000/testtomcat latest 365b0a528e2e 4 days ago 506MB
tomcat latest 365b0a528e2e 4 days ago 506MB
registry latest f32a97de94e1 6 months ago 25.8MB #提交镜像到到docker私服
[root@localhost home]# docker push 127.0.0.1:5000/testtomcat
The push refers to repository [127.0.0.1:5000/testtomcat]
4a3ccf95eef9: Pushed
4437177a7bda: Pushed
5161954b2663: Pushed
57e6a3d20ce9: Pushed
1690af51cb08: Pushed
5a30999619d7: Pushed
2e669e0134f5: Pushed
8bacec4e3446: Pushed
26b1991f37bd: Pushed
55e6b89812f3: Pushed
latest: digest: sha256:416e93b104aa4bceff6005ec6cc4e073196f98d8e3aa4564c3f7d6ad3591d767 size: 2422 #curl验证
[root@localhost home]# curl http://127.0.0.1:5000/v2/_catalog
{"repositories":["testtomcat"]}

3. 拉取镜像

 #查看镜像
[root@localhost home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest f32a97de94e1 6 months ago 25.8MB #拉取docker私服镜像
[root@localhost home]# docker pull 127.0.0.1:5000/testtomcat
Using default tag: latest
latest: Pulling from testtomcat
092586df9206: Pull complete
ef599477fae0: Pull complete
4530c6472b5d: Pull complete
d34d61487075: Pull complete
272f46008219: Pull complete
12ff6ccfe7a6: Pull complete
f26b99e1adb1: Pull complete
21bec9c8ea28: Pull complete
e2f6023231f2: Pull complete
c47eb491a5e3: Pull complete
Digest: sha256:416e93b104aa4bceff6005ec6cc4e073196f98d8e3aa4564c3f7d6ad3591d767
Status: Downloaded newer image for 127.0.0.1:5000/testtomcat:latest #再次查看镜像
[root@localhost home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
127.0.0.1:5000/testtomcat latest 365b0a528e2e 4 days ago 506MB
registry latest f32a97de94e1 6 months ago 25.8MB

4.删除私服镜像

 # 查看当前docker私服中的镜像
[root@localhost ~]# curl http://127.0.0.1:5000/v2/_catalog
{"repositories":["mingbytesiteweb"]} # 查看docker私服容器,重点是 CONTAINER ID
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
67b0ac405616 registry:latest "/entrypoint.sh /etc…" 44 hours ago Up 44 hours 0.0.0.0:5000->5000/tcp qdockerhub # 删除docker私服中的“mingbytesiteweb”镜像
# 其中67b0ac405616 为docker私服容器id
[root@localhost ~]# docker exec 67b0ac405616 rm -rf /var/lib/registry/docker/registry/v2/repositories/mingbytesiteweb # 清除掉blob
# 67b0为docker私服容器id
[root@localhost ~]# docker exec 67b0 bin/registry garbage-collect /etc/docker/registry/config.yml 0 blobs marked, 9 blobs and 0 manifests eligible for deletion
blob eligible for deletion: sha256:a381f92f36de52ade5b5610ef1b354713f21902b2ef32abf8f5101daf686e6b4
blob eligible for deletion: sha256:cce6b5d4a535e729c30f1f9140a61e5fe408250c442ad69569612094970f8035
blob eligible for deletion: sha256:d5c237920c394bda8bf1ef31b00bbde458f6978c159303e00d712a95c3f32a40
time="2019-09-20T02:53:41.576433178Z" level=info msg="Deleting blob: /docker/registry/v2/blobs/sha256/a3/a381f92f36de52ade5b5610ef1b354713f21902b2ef32abf8f5101daf686e6b4" go.version=go1.11.2 instance.id=ded69299-53f9-4ffe-9309-a707264a7549 service=registry
time="2019-09-20T02:53:41.576740825Z" level=info msg="Deleting blob: /docker/registry/v2/blobs/sha256/cc/cce6b5d4a535e729c30f1f9140a61e5fe408250c442ad69569612094970f8035" go.version=go1.11.2 instance.id=ded69299-53f9-4ffe-9309-a707264a7549 service=registry
time="2019-09-20T02:53:41.577819834Z" level=info msg="Deleting blob: /docker/registry/v2/blobs/sha256/d5/d5c237920c394bda8bf1ef31b00bbde458f6978c159303e00d712a95c3f32a40" go.version=go1.11.2 instance.id=ded69299-53f9-4ffe-9309-a707264a7549 service=registry
blob eligible for deletion: sha256:f17d81b4b692f7e0d6c1176c86b81d9f2cb5ac5349703adca51c61debcfe413c
blob eligible for deletion: sha256:01fe0503c7f786c0613596ab151412f7fd68874d80c43289e5c32725ef1c52ff
blob eligible for deletion: sha256:082bd21a11cbf8765d11f10147dc59639118b0700c43a6eef427059faa99e939
blob eligible for deletion: sha256:396a68a9a5c5ed3ab7b570199a9daee6b468b5cacd4e2a6d0040e3ea7c9bb891
blob eligible for deletion: sha256:3ba74338e49429d19a7e6609eee9f16faa369aa30cdcc295b5382999afa3143a
blob eligible for deletion: sha256:5ed7726b81ebb228b250e4ef703ec976b56f8db47d5d9f82ce93ebb026fc6e5f
time="2019-09-20T02:53:41.58367518Z" level=info msg="Deleting blob: /docker/registry/v2/blobs/sha256/f1/f17d81b4b692f7e0d6c1176c86b81d9f2cb5ac5349703adca51c61debcfe413c" go.version=go1.11.2 instance.id=ded69299-53f9-4ffe-9309-a707264a7549 service=registry
time="2019-09-20T02:53:41.58874132Z" level=info msg="Deleting blob: /docker/registry/v2/blobs/sha256/01/01fe0503c7f786c0613596ab151412f7fd68874d80c43289e5c32725ef1c52ff" go.version=go1.11.2 instance.id=ded69299-53f9-4ffe-9309-a707264a7549 service=registry
time="2019-09-20T02:53:41.589391384Z" level=info msg="Deleting blob: /docker/registry/v2/blobs/sha256/08/082bd21a11cbf8765d11f10147dc59639118b0700c43a6eef427059faa99e939" go.version=go1.11.2 instance.id=ded69299-53f9-4ffe-9309-a707264a7549 service=registry
time="2019-09-20T02:53:41.589628015Z" level=info msg="Deleting blob: /docker/registry/v2/blobs/sha256/39/396a68a9a5c5ed3ab7b570199a9daee6b468b5cacd4e2a6d0040e3ea7c9bb891" go.version=go1.11.2 instance.id=ded69299-53f9-4ffe-9309-a707264a7549 service=registry
time="2019-09-20T02:53:41.589939086Z" level=info msg="Deleting blob: /docker/registry/v2/blobs/sha256/3b/3ba74338e49429d19a7e6609eee9f16faa369aa30cdcc295b5382999afa3143a" go.version=go1.11.2 instance.id=ded69299-53f9-4ffe-9309-a707264a7549 service=registry
time="2019-09-20T02:53:41.590973494Z" level=info msg="Deleting blob: /docker/registry/v2/blobs/sha256/5e/5ed7726b81ebb228b250e4ef703ec976b56f8db47d5d9f82ce93ebb026fc6e5f" go.version=go1.11.2 instance.id=ded69299-53f9-4ffe-9309-a707264a7549 service=registry
  # 删除完成
[root@localhost ~]# curl http://127.0.0.1:5000/v2/_catalog
{"repositories":[]}

错误集合

a. 运行错误1

错误提示: [root@izj6c0zsm04q86s2tu4e12z /]# docker run -it docker.io/ubuntu:latest /bin/bash
/usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:235: starting container process caused "process_linux.go:258: applying cgroup configuration for process caused \"Cannot set property TasksAccounting, or unknown property.\"".

解决办法: yum update

b. 私有仓库push错误(改配置后一定要重启docker)

  • docker私有仓库的5000端口是否在防火墙中打开

  • daemon.json文件中提交镜像的地址是否修改为私有docker仓库的地址

  • 添加镜像仓库地址insecure-registries参数,内容修改如下:

vim /etc/docker/daemon.json
{
"registry-mirrors":["https://registry.docker-cn.com"],
"insecure-registries":["47.240.32.247:5000"]
}

[root@localhost bin]# systemctl daemon-reload
[root@localhost bin]# systemctl restart docker

 

最新文章

  1. IIS连接数、IIS并发连接数、IIS最大并发工作线程数、应用程序池的队列长度、应用程序池的
  2. cloudera learning4:Hadoop集群规划
  3. SVN使用教程
  4. UIButton中setTitleEdgeInsets和setImageEdgeInsets的使用
  5. MVC3不能正确识别JSON中的Enum枚举值
  6. ZZULIOJ 1726 迷宫(BFS+小坑)
  7. ExpandableListView实现子Item的点击事件
  8. Android selector item 属性大全(按钮按下不同效果)
  9. 用java pyhont通过HTTP协议传输文件流
  10. CC++初学者编程教程(5) 安装codeblocks软件开发环境
  11. NEFUOJ 500 二分法+最大流量
  12. 正则表达式(c#)
  13. C++\virtual 虚函数、纯虚函数
  14. 在 TensorFlow 中实现文本分类的卷积神经网络
  15. 产品 vs 服务,见识,耐心
  16. String.Join Method
  17. 【English】20190326
  18. 微服务领域是不是要变天了?Spring Cloud Alibaba正式入驻Spring Cloud官方孵化器!
  19. Golang源码探索(一) 编译和调试源码(转)
  20. Vue的从入门到放弃

热门文章

  1. Ubuntu系统开发环境完整搭建
  2. idea设置docker远程插件
  3. 神经网络 OCR 参考
  4. 9406LaTeX公式
  5. Liunx学习总结(八)--服务
  6. unity游戏开发_对象池
  7. [PHP] 遗传算法求函数最大值一般实现
  8. electron-vue-webpack引入bootstrap多实例问题Multiple instances of Vue detected!
  9. UVALive 7264 Kejin Game 网络流+最小割
  10. Js、layui获取单选框radio的几种方法