其他分享
首页 > 其他分享> > 搭建docker私有仓库

搭建docker私有仓库

作者:互联网

1.Docker Hub私有仓库篇

Docker Hub是官方的镜像仓库,国内访问可能会比较慢。我个人比较多使用阿里云的私有仓库。

1.1完整步骤

#先注册账户:https://hub.docker.com

docker login #登录个人仓库,输入账号密码

docker pull hello-world #拉取一个镜像做演示

docker images #查看拉取的镜像,获取镜像ID:d1165f221234

docker tag d1165f221234 用户/hello-world:1.0 #镜像重新命名,用户/仓库:标签

docker push 用户/hello-world:1.0 #推送镜像到私有仓库

docker pull 用户/hello-world:1.0 #从私有仓库拉取镜像

docker logout #退出个人仓库

1.2补充

官方镜像默认是从library拉取,可以配置镜像加速。

image

推送到私有仓库:

image

docker hub私有仓库上传镜像成功:

image

2.阿里云私有仓库篇

2.1创建私有仓库

1.开通私有仓库地址:https://cr.console.aliyun.com/cn-hangzhou/instance/new

2.进入容器镜像服务,我这里选中创建个人实例,会提示设置开通服务密码
image

3.创建镜像仓库,注意命名空间,拉取或推送私有仓库命令行需要用到。如:docker pull registry.cn-hangzhou.aliyuncs.com/命名空间/hello-world:[镜像版本号]
image

4.到这里一个阿里云私有仓库就创建好了,可以在界面看到私有仓库地址和管理仓库。
image

2.2连接私有仓库

  1. 登录阿里云Docker Registry
$ docker login --username=用户名 registry.cn-hangzhou.aliyuncs.com

用于登录的用户名为阿里云账号全名,密码为开通服务时设置的密码。

  1. 从Registry中拉取镜像
$ docker pull registry.cn-hangzhou.aliyuncs.com/命名空间/hello-world:[镜像版本号]
  1. 将镜像推送到Registry
$ docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/命名空间/hello-world:[镜像版本号]
$ docker push registry.cn-hangzhou.aliyuncs.com/命名空间/hello-world:[镜像版本号]
  1. 选择合适的镜像仓库地址

从ECS推送镜像时,可以选择使用镜像仓库内网地址。推送速度将得到提升并且将不会损耗您的公网流量。如果您使用的机器位于VPC网络,请使用 registry-vpc.cn-hangzhou.aliyuncs.com 作为Registry的域名登录。

因为我的宿主机是阿里云服务器,所以推荐使用下面命令:

#从私有仓库拉取:
docker pull registry-vpc.cn-hangzhou.aliyuncs.com/命名空间/仓库名:[镜像版本号]

#推送到私有仓库:
docker tag 镜像ID registry-vpc.cn-hangzhou.aliyuncs.com/命名空间/仓库名:[镜像版本号]
docker push registry-vpc.cn-hangzhou.aliyuncs.com/命名空间/仓库名:[镜像版本号]

标签:私有,仓库,hangzhou,镜像,docker,com,搭建
来源: https://www.cnblogs.com/tang-hao/p/14857133.html