docker仓库的搭建以及使用

 docker仓库的搭建以及使用_第1张图片

 

目录

一、使用aliyun的registry上传下载镜像https://cr.console.aliyun.com/cn-hangzhou/repositories

1.先在阿里云注册一个本地仓库

2.给镜像打上标签

3.在docker上登陆自己的阿里云账号

4.把镜像上传到阿里云

5.查看是否成功

6.删除本地镜像

7.下拉镜像到本地

二、使用registry镜像运行容器上传下载镜像


一、使用aliyun的registry上传下载镜像

https://cr.console.aliyun.com/cn-hangzhou/repositories

 

1.先在阿里云注册一个本地仓库

容器镜像服务 (aliyun.com)icon-default.png?t=M7J4https://cr.console.aliyun.com/cn-hangzhou/instance/repositories

2.给镜像打上标签

[root@bingbing ~]# docker tag alpine:latest maxuedong/alpine:latest
[root@bingbing ~]# docker images

REPOSITORY         TAG       IMAGE ID       CREATED         SIZE
busybox            v1        0a141ab55662   4 hours ago     1.24MB
maxuedong/alpine   latest    9c6f07244728   11 days ago     5.54MB
alpine             latest    9c6f07244728   11 days ago     5.54MB
php                latest    4d6ad64a864a   2 weeks ago     484MB
nginx              latest    b692a91e4e15   2 weeks ago     142MB
busybox            latest    7a80323521cc   3 weeks ago     1.24MB
hello-world        latest    feb5d9fea6a5   11 months ago   13.3kB
tencentci/discuz   lasest    4833f513a33c   13 months ago   463MB

3.在docker上登陆自己的阿里云账号

[root@bingbing ~]# docker login --username=q1434870588 registry.cn-hangzhou.aliyuncs.com
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
 

4.把镜像上传到阿里云

[root@bingbing ~]# docker tag alpine:latest  registry.cn-hangzhou.aliyuncs.com/daroubaozi/dockers:v1

[root@bingbing ~]# docker push registry.cn-hangzhou.aliyuncs.com/daroubaozi/dockers:v1
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/daroubaozi/dockers]
994393dc58e7: Pushed 
v1: digest: sha256:1304f174557314a7ed9eddb4eab12fed12cb0cd9809e4c28f29af86979a3c870 size: 528
 

5.查看是否成功

docker仓库的搭建以及使用_第2张图片

 

6.删除本地镜像

[root@bingbing ~]# docker image rm alpine:latest 
Untagged: alpine:latest
Untagged: alpine@sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad

7.下拉镜像到本地

[root@bingbing ~]# docker pull registry.cn-hangzhou.aliyuncs.com/daroubaozi/dockers:v1
v1: Pulling from daroubaozi/dockers
Digest: sha256:1304f174557314a7ed9eddb4eab12fed12cb0cd9809e4c28f29af86979a3c870
Status: Image is up to date for registry.cn-hangzhou.aliyuncs.com/daroubaozi/dockers:v1
registry.cn-hangzhou.aliyuncs.com/daroubaozi/dockers:v1
 

二、使用registry镜像运行容器上传下载镜像

1.拉取registry镜像

[root@bingbing ~]# docker pull registry

 

2.启动registry容器

[root@bingbing docker]# docker run --name registry -p 5000:5000 -v /data/registry:/var/lib/registry -d registry:2.6.2 
 

3.打上标签

[root@bingbing docker]# docker image tag nginx:1.14-alpine 49.234.46.66:5000/nginx:1.14
 

4.修改/etc/docker/daemon.json配置文件

[root@bingbing ~]# vim /etc/docker/daemon.json
[root@bingbing ~]# cat /etc/docker/daemon.json

{
registry-mirrors": ["https://jkeshucp.mirror.aliyuncs.com","https://mirror.ccs.tencentyun.com"],
  "insecure-registries": ["49.234.46.66:5000"]
}


 

5.重启docker和 重启容器

需要修改daemon.json 文件的后缀名为daemon.demo 不然会报错,重启后改回来

[root@bingbing docker]# sudo mv daemon.conf daemon.json
 

systemctl restart docker 
 docker restart registry 

[root@bingbing docker]# sudo mv daemon.json daemon.conf

6.上传镜像

docker push 49.234.46.66:5000/nginx:1.14

7. 删除镜像

docker image rm 49.234.46.66:5000/nginx:1.14

 8.拉取镜像

docker pull 49.234.46.66:5000/nginx:1.14

你可能感兴趣的:(Docker,docker,容器,运维)