Centos7 docker基础3-仓库

  1. 创建和使用私有仓库

仓库(repository):放镜像的地方

创建和使用私有仓库

安装docker后 可以通过宣官方提供的registry镜像本搭建一套本地私有仓库环境

[root@centos7 /]# docker pull registry
Using default tag: latest
Trying to pull repository docker.io/library/registry ... 
latest: Pulling from docker.io/library/registry
c87736221ed0: Pull complete 
1cc8e0bb44df: Pull complete 
54d33bcb37f5: Pull complete 
e8afc091c171: Pull complete 
b4541f6d3db6: Pull complete 
Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146
Status: Downloaded newer image for docker.io/registry:latest
[root@centos7 /]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
centos1                   v1.0                f1420ae8ab97        26 minutes ago      202 MB
ubuntu                    14.04               40446eeefc1a        8 hours ago         215 MB
docker.io/rdocker8/test   latest              8e861c8118a3        8 hours ago         64.2 MB
docker.io/ubuntu          latest              4c108a37151f        4 weeks ago         64.2 MB
docker.io/centos          latest              9f38484d220f        4 months ago        202 MB
docker.io/registry        latest              f32a97de94e1        4 months ago        25.8 MB
[root@centos7 /]# mkdir -p /opt/data/registry
docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
-p 开启端口映射  本地端口:容器端口
-v 开启目录映射  本地目录:容器目录
[root@centos7 /]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry

140c9a4ac310113ed77e1e9660fe9607e1654e0c8c34f364bf89756f90dafb01
[root@centos7 /]# docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
140c9a4ac310        registry            "/entrypoint.sh /e..."   12 seconds ago      Up 10 seconds       0.0.0.0:5000->5000/tcp   awesome_booth
[root@centos7 /]# netstat -tuplan | grep 5000
tcp6       0      0 :::5000                 :::*                    LISTEN      9549/docker-proxy-c 
[root@centos7 ~]# curl 127.0.0.1:5000/v2
<a href="/v2/">Moved Permanently</a>.

尝试上传一个镜像

docker tage image registryhost/[username/]name[:TAG]
[root@centos7 ~]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
docker.io/ubuntu          latest              4c108a37151f        4 weeks ago         64.2 MB
docker.io/registry        latest              f32a97de94e1        4 months ago        25.8 MB
[root@centos7 ~]# docker tag ubuntu 192.168.174.102:5000/ubuntu #要使用IP:5000/标签的方式 
[root@centos7 ~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
192.168.174.102:5000/ubuntu   latest              4c108a37151f        4 weeks ago         64.2 MB
docker.io/ubuntu              latest              4c108a37151f        4 weeks ago         64.2 MB
docker.io/registry        latest              f32a97de94e1        4 months ago        25.8 MB
[root@centos7 ~]# docker push 192.168.174.102:5000/ubuntu
The push refers to a repository [192.168.174.102:5000/ubuntu]
Get https://192.168.174.102:5000/v1/_ping: http: server gave HTTP response to HTTPS client

#添加daemon.json 内容为如下: 其中192.168.174.102是仓库所在的IP

[root@centos7 docker]# cat /etc/docker/daemon.json 
{ "insecure-registries":["192.168.174.102:5000"]}
systemctl  reload docker.service   #要重启下docker服务

再次上传

[root@centos7 docker]# docker push 192.168.174.102:5000/ubuntu
The push refers to a repository [192.168.174.102:5000/ubuntu]
75e70aa52609: Pushed 
dda151859818: Pushed 
fbd2732ad777: Pushed 
ba9de9d8475e: Pushed 
latest: digest: sha256:eb70667a801686f914408558660da753cde27192cd036148e58258819b927395 size: 1152 #上传成功
[root@centos7 docker]# 
[root@centos7 docker]#  curl -XGET http://192.168.174.102:5000/v2/_catalog
{"repositories":["ubuntu"]}

上传成功

做私人仓库 还有很多要做的比如做CA证书、安全认证等 还可以添加 web UI 的界面 回来再继续做仓库

参考:https://blog.csdn.net/egworkspace/article/details/80518647
教程参考于:http://www.bdkyr.com/


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。

文章标题:Centos7 docker基础3-仓库

本文作者:wangzhirui

发布时间:2019-08-22, 17:00:27

最后更新:2025-02-27, 02:04:03

原始链接:https://wangzhirui.com/2019/08/22/Centos7-docker基础3-仓库/

转载请保留原文链接及作者。

目录