2023-12-07
Docker
00

目录

Docker 镜像发布(七)
一、发布镜像到阿里云镜像仓库 🍒
1、配置阿里云镜像仓库
(1)配置容器镜像服务
(2)创建命名空间
(3)创建镜像仓库和仓库代码源
2、上传本地镜像至阿里云镜像仓库
(1)登录阿里云Docker Regist
(2)制作镜像 tag
(3)将镜像推送到 阿里云镜像仓库
(4)从阿里云镜像仓库拉取镜像到本地
二、发布镜像到本地私有镜像仓库 🍉
1、私有仓库搭建
(1)私有仓库镜像下载
(2)运行私有仓库镜像
(3)修改配置文件
(4)重启 docker
2、上传本地镜像至本地仓库
(1)制作镜像tag
(2)推送镜像至本地私有镜像仓库
(3)查看本地私有镜像仓库镜像
(4)查看私有仓库镜像 tag
(5) 从私有仓库拉取镜像到本地

Docker 镜像发布(七)

本文介绍如何将镜像发布到阿里云镜像仓库和本地私有仓库,以及本地私有仓库部署。

Docker 镜像发布(七)

https://image.myxuechao.com/docker/23.png

一、发布镜像到阿里云镜像仓库 🍒

1、配置阿里云镜像仓库

(1)配置容器镜像服务

阿里云登录 - 欢迎登录阿里云,安全稳定的云计算服务平台

登录阿里云官网,找到容器镜像服务,如果没有则手动创建一个,如下图所示:

https://image.myxuechao.com/docker/24.png

(2)创建命名空间

https://image.myxuechao.com/docker/25.png

https://image.myxuechao.com/docker/26.png

(3)创建镜像仓库和仓库代码源

https://image.myxuechao.com/docker/27.png

https://image.myxuechao.com/docker/28.png

2、上传本地镜像至阿里云镜像仓库

示例:将本地镜像 myubuntu:v1 推送到阿里云仓库

(1)登录阿里云Docker Regist

bash
[root@10-60-55-35 ~]# docker login --username=aliyun8029235972 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

(2)制作镜像 tag

bash
[root@10-60-55-35 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest a6bd71f48f68 13 days ago 187MB 6053537/portainer-ce latest b9c565f94ccc 5 weeks ago 322MB portainer/helper-reset-password latest c56588a8080c 6 months ago 43.5MB hello-world latest 9c7a54a9a43c 7 months ago 13.3kB [root@10-60-55-35 ~]# docker tag a6bd71f48f68 registry.cn-hangzhou.aliyuncs.com/lxc_blog/blog:latest [root@10-60-55-35 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest a6bd71f48f68 13 days ago 187MB registry.cn-hangzhou.aliyuncs.com/lxc_blog/blog latest a6bd71f48f68 13 days ago 187MB

(3)将镜像推送到 阿里云镜像仓库

bash
docker push registry.cn-hangzhou.aliyuncs.com/lxc_blog/blog:1.0.0

(4)从阿里云镜像仓库拉取镜像到本地

bash
docker pull registry.cn-hangzhou.aliyuncs.com/lxc_blog/blog:1.0.0

二、发布镜像到本地私有镜像仓库 🍉

1、私有仓库搭建

(1)私有仓库镜像下载

bash
docker pull registry

(2)运行私有仓库镜像

bash
docker run -d -p 5000:5000 -v /data/myregistry:/tmp/registry --privileged=true registry

(3)修改配置文件

  • 修改配置文件使之支持http
  • 编辑 daemon.json 上述理由:docker默认不允许http方式推送镜像,通过配置选项来取消这个限制。====>修改完后如果不生效,建议重启docker
bash
[root@localhost ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["https://6l7dxkas.mirror.aliyuncs.com"], "insecure-registries": ["192.168.6.80:5000"] }

注意:配置文件格式为json格式,条目之间要有空格分隔。

(4)重启 docker

bash
systemctl restart docker

2、上传本地镜像至本地仓库

示例:将本地镜像 nginx:latest 推送到阿里云仓库

(1)制作镜像tag

bash
[root@10-60-55-35 ~]# docker tag nginx:latest 117.50.172.33:5000/nginx:latest [root@10-60-55-35 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry latest 909c3ff012b7 3 days ago 25.4MB 117.50.172.33:5000/nginx latest a6bd71f48f68 13 days ago 187MB nginx latest a6bd71f48f68 13 days ago 187MB

(2)推送镜像至本地私有镜像仓库

bash
docker push 117.50.172.33:8080/nginx:latest

(3)查看本地私有镜像仓库镜像

bash
[root@localhost ~]# curl 117.50.172.33:5000/v2/_catalog {"repositories":["mynginx"]}

(4)查看私有仓库镜像 tag

bash
[root@localhost ~]# curl -XGET http://117.50.172.33:5000/v2/nginx/tags/list {"name":"mynginx","tags":["1.2"]}

(5) 从私有仓库拉取镜像到本地

bash
docker pull 117.50.172.33:5000/nginx:1.2
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:LiuXueChao

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!