Docker本地镜像推送到自建私有仓库
搭建私有仓库
搭建仓库采用Docker官方的 registry 镜像。
官方文档:https://docs.docker.com/registry/
1. 下载镜像
docker pull registry
2. 运行容器
docker run -d -p 5000:5000 -v /data/myregistry/:/tmp/registry --privileged=true registry
3. 查看私服
查看当前私服有哪些镜像
[root@localhost ~]# curl -XGET http://192.168.92.146:5000/v2/_catalog {"repositories":[]}
当前没有。
构建本地镜像
基于ubuntu镜像,添加ifconfig命令。
[root@localhost ~]# docker run -it ubuntu /bin/bash root@4c19d8b129bd:/# apt-get update root@4c19d8b129bd:/# apt-get install -y net-tools # 添加 ifconfig 命令
Ctrl+p+q 退出。
使用commit提交新的镜像:
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4c19d8b129bd ubuntu "/bin/bash" 3 minutes ago Up 3 minutes distracted_raman 29c9e97c1edc registry "/entrypoint.sh /etc…" 4 minutes ago Up 4 minutes 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp intelligent_fermi [root@localhost ~]# docker commit -m="Add ifconfig command" -a="Alex" 4c19d8b129bd alex/ubuntu:v1.2 sha256:5ae571578dc43d97fdef4435c057149749dbb8ae4034a84fbb5e2c5a7b0db752 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE alex/ubuntu v1.2 5ae571578dc4 4 seconds ago 108MB registry.cn-beijing.aliyuncs.com/chenxie/ubuntu v1.0 80e71251231c About an hour ago 175MB registry latest b8604a3fe854 3 months ago 26.2MB ubuntu latest ba6acccedd29 4 months ago 72.8MB
推送到私服
打Tag
将 alex/ubuntu:v1.2 重新打为符合私服规范的Tag:
[root@localhost ~]# docker tag alex/ubuntu:v1.2 192.168.92.146:5000/alex/ubuntu:v1.2 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.92.145:5000/alex/ubuntu v1.2 5ae571578dc4 8 minutes ago 108MB alex/ubuntu v1.2 5ae571578dc4 8 minutes ago 108MB
修改配置文件使之支持http推送
修改配置文件使之支持http推送,不然会报:Get "https://192.168.92.146:5000/v2/": http: server gave HTTP response to HTTPS client
vim /etc/docker/daemon.json
改为如下:
{ "registry-mirrors": ["https://cvy84kji.mirror.aliyuncs.com"], "insecure-registries": ["192.168.92.146:5000"] }
注意:不要忘记加逗号。
重新加载docker配置:systemctl reload docker
推送
[root@localhost ~]# docker push 192.168.92.146:5000/alex/ubuntu:v1.2 The push refers to repository [192.168.92.146:5000/alex/ubuntu] 1ca6a59fa47a: Pushed 9f54eef41275: Pushed v1.2: digest: sha256:507180f5b6dfc2455c15a359bf295d1ab680e8397624c8f9628199142c129a7f size: 741
再次查看私服:
[root@localhost ~]# curl -XGET http://192.168.92.146:5000/v2/_catalog {"repositories":["alex/ubuntu"]}
有了新的镜像。
拉取测试
[root@localhost ~]# docker pull 192.168.92.146:5000/alex/ubuntu:v1.2 v1.2: Pulling from alex/ubuntu 7b1a6ab2e44d: Already exists 8b0fe7c91193: Already exists Digest: sha256:507180f5b6dfc2455c15a359bf295d1ab680e8397624c8f9628199142c129a7f Status: Downloaded newer image for 192.168.92.145:5000/alex/ubuntu:v1.2 192.168.92.145:5000/alex/ubuntu:v1.2 [root@localhost ~]# [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.92.145:5000/alex/ubuntu v1.2 5ae571578dc4 22 minutes ago 108MB
文章目录
关闭
共有 0 条评论