work hard work smart

专注于Java后端开发。 不断总结,举一反三。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

镜像仓库

Posted on 2020-05-22 13:32  work hard work smart  阅读(307)  评论(0编辑  收藏  举报

1、上传镜像到公有仓库 hub.docker.com

1)、登录https://hub.docker.com/ 创建账号

2)、docker images

找一个小一点的images,如hello-world

 

 

 3)、打上tag

docker tag hello-world:latest  larry003/hello-world:latest

larry003 是docker hub上的用户名

4)登录docker hub

docker login

 

5)将镜像上传

docker push larry003/hello-world:latest

 

2、私有仓库registry使用

1)打开 https://hub.docker.com, 搜索registry

 2) 下载registry版本2 
   docker pull registry:2
3) 运行镜像
  docker run -d -p 5000:5000 registry:2

4) 打上tag

docker tag hello-world:latest localhost:5000/hello-world:latest

5) 推送镜像

docker push localhost:5000/hello-world:latest

总结:这样私有仓库就创建起来了。

缺点:生产环境的单点问题,如果这条服务器故障了,其它服务器很难接管过来。

           没有操作界面。

 

3、私有镜像仓库harbor的使用

harbor解决了registry的问题

1)、下载harbor

在github上下载harbor https://github.com/goharbor/harbor

下载1.2.2版本 harbor-offline-installer-v1.2.2.tgz

https://github.com/goharbor/harbor/releases/tag/v1.2.2

2) 修改hostname

/root/dockerDeploy/app/harbor

harbor.cfg

hostname为外网 或者域名

 

 这里默认使用80端口

 

 

3) 安装./install.sh

4) 安装成功后访问

 

5) 登录harbor

默认用户名 admin

默认密码: Harbor12345

 

6) 创建一个私有的项目microservice

 

 

 

 

7) 复制功能

 

 

假如我们的服务部署在多个机房。机房内的网速很快,但是机房之间的网速则很慢。

这样可以在每个机房部署一个harbor,通过一个中心的harbor,当它有镜像的时候,自动同步到其它镜像服务器。

 

8) 添加用户

 

 

9) 创建的项目中添加成员

 

10) 将镜像推送到创建的私有仓库里

    1) 将镜像打上Tag

docker tag hello-world:latest  xx.xx.xx.xx/microservice/hello-world:latest

 

 

     2)   将镜像推送的仓库,出现如下错误

     docker push xx.xx.xx.xx/microservice/hello-world:latest

   推送的时候,出现如下两个错误:

问题1: 443的连接拒绝

 

 解决方法:

vi /usr/lib/systemd/system/docker.service

增加--insecure-registry xx.xx.xx.xx

 

 

 

问题2: denied: equested access to resource is denied

解决方法: 登录私有仓库

        docker login xx.xx.xx.xx

 

 再次Push,可以发现Push成功

可以发现可以在浏览器中查看刚才推送的镜像

 

  11) 构建微服务镜像,并推送的私有仓库

    修改DockerFile文件。修改From

 

 

 

构建镜像

docker build -t 4x.xx.xx.120/microservice/api-gateway-zuul:latest .

推送镜像
docker push 4x.xx.xx.120/microservice/api-gateway-zuul:latest