docker 搭建本地仓库

1. 环境准备

Linux版本:Centos7

docker版本:17.05.0-ce

2. 部署Registry

使用docker pull命令获取registry的image

# sudo docker pull registry:2.1.1

使用docker run使用下载的registry的image启动一个容器

# sudo docker run -d -p 5000:5000 -v /opt/registry:/var/lib/registry --restart=always --name registry registry:2.1.1

查看启动的容器

# sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
ebb16548e9d3        registry:2.1.1      "/bin/registry /et..."   12 seconds ago      Up 11 seconds       0.0.0.0:5000->5000/tcp   registry 

打开浏览器,访问http://IP:5000/v2/_catalog,可以查看到{"repositories": []}表示现在仓库中,没有镜像images

现在,下载一个镜像,然后传到本地仓库中,以下以busybox镜像为例

# sudo docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
27144aa8f1b9: Pull complete 
Digest: sha256:be3c11fdba7cfe299214e46edc642e09514dbb9bbefcd0d3836c05a1e0cd0642
Status: Downloaded newer image for busybox:latest
# sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED                  SIZE
busybox             latest              c30178c5239f        Less than a second ago   1.11 MB
hello-world         latest              1815c82652c0        20 hours ago             1.84 kB
registry            2.1.1               52bb991b482e        20 months ago            220 MB
在本地host上面,给busybox添加新的tag
# sudo docker tag busybox 192.168.61.128:5000/busybox
# sudo docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED                  SIZE
192.168.61.128:5000/busybox   latest              c30178c5239f        Less than a second ago   1.11 MB
busybox                       latest              c30178c5239f        Less than a second ago   1.11 MB
hello-world                   latest              1815c82652c0        20 hours ago             1.84 kB
registry                      2.1.1               52bb991b482e        20 months ago            220 MB 
将镜像上传到仓库中
# sudo docker push 192.168.61.128:5000/busybox
The push refers to a repository [192.168.61.128:5000/busybox]
Get https://192.168.61.128:5000/v1/_ping: http: server gave HTTP response to HTTPS client 
出现上述提示,表示本地的仓库默认使用的是https进行上传,如果是非https就会出现以上的提示

解决方式,可以参考一下方式

修改文件/usr/lib/systemd/system/docker.service,在ExecStart=/usr/bin/dockerd后面添加--insecure-registry 192.168.61.128:5000,然后重启docker服务

# cat /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target firewalld.service

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --insecure-registry 192.168.61.128:5000
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process

[Install]
WantedBy=multi-user.target
# sudo systemctl daemon-reload && sudo systemctl restart docker.service
重新上传
# sudo docker push 192.168.61.128:5000/busybox
The push refers to a repository [192.168.61.128:5000/busybox]
3a1dff9afffd: Pushed 
latest: digest: sha256:417ae70baa235876876e723f4b630afa7f91a113025d70361597656b5cf0481b size: 2136

打开浏览器,访问http://IP:5000/v2/_catalog,可以查看到{"repositories": ["busybox"]}表示现在仓库中,存在镜像busybox这一个

猜你喜欢

转载自blog.csdn.net/qq_22083251/article/details/80853164