我是靠谱客的博主 真实乌龟,最近开发中收集的这篇文章主要介绍docker搭建局域网私有仓库1. 环境2. docker pull registry 拉取官方仓库镜像3. 用刚拉取的镜像启动容器4. 查看本地仓库curl 127.0.0.1:5000/v2/_catalog5. push本地镜像到私有仓库,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

  • author:@c1awn
  • env如下:

如无特殊说明,docker版本为:

[root@c1awn01 ~]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: <unknown>
 Go version:      go1.8.3
 Git commit:      774336d/1.13.1
 Built:           Wed Mar  7 17:06:16 2018
 OS/Arch:         linux/amd64

linux版本:

[root@c1awn01 ~]# uname -a
Linux c1awn01 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 19:03:37 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@c1awn01 ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

1. 环境

局域网,其中一台服务器 192.168.80.129 搭建私有仓库

[root@c1awn01 ~]# ifconfig 
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.80.129  netmask 255.255.255.0  broadcast 192.168.80.255
        inet6 fe80::40f6:3aff:fea8:f59f  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:0a:39:12  txqueuelen 1000  (Ethernet)
        RX packets 1946  bytes 10795075 (10.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1657  bytes 132553 (129.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
        inet6 fe80::42:71ff:fe8e:ba62  prefixlen 64  scopeid 0x20<link>
        ether 02:42:71:8e:ba:62  txqueuelen 0  (Ethernet)
        RX packets 33  bytes 2504 (2.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 37  bytes 3760 (3.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2. docker pull registry 拉取官方仓库镜像

[root@c1awn01 ~]# docker pull registry
Using default tag: latest
Trying to pull repository docker.io/library/registry ... 
latest: Pulling from docker.io/library/registry
81033e7c1d6a: Pull complete 
b235084c2315: Pull complete 
c692f3a6894b: Pull complete 
ba2177f3a70e: Pull complete 
a8d793620947: Pull complete 
Digest: sha256:994aaf8dfeaaa06ba7d2ec1d6d60d748697a980e48c2fa14d0e4a6d4920bd5b1
Status: Downloaded newer image for docker.io/registry:latest

3. 用刚拉取的镜像启动容器

[root@c1awn01 ~]# docker run -d -p 5000:5000 docker.io/registry 
b350ddcaa8d5d3595284b193118d020e52cb296cf563de13e7c843cb02f8c27c
[root@c1awn01 ~]# docker ps 
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                    NAMES
b350ddcaa8d5        docker.io/registry   "/entrypoint.sh /e..."   5 seconds ago       Up 4 seconds        0.0.0.0:5000->5000/tcp   happy_bassi

4. 查看本地仓库curl 127.0.0.1:5000/v2/_catalog

ip和端口根据你自己的实际情况,后面的目录得是这样

[root@c1awn01 ~]# curl 127.0.0.1:5000/v2/_catalog
{"repositories":[]}

"repositories":[]中括号为空,说明仓库已搭建,且没有镜像

5. push本地镜像到私有仓库

1. 查看本地镜像

[root@c1awn01 ~]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
nginx                       latest              f1280371d1cb        17 hours ago        109 MB
test_nginx                  latest              8947401b76ed        18 hours ago        109 MB
centos/zip                  latest              c7ce05084477        3 days ago          302 MB
docker.io/nginx             latest              ae513a47849c        12 days ago         109 MB
docker.io/centos            latest              e934aafc2206        5 weeks ago         199 MB
docker.io/registry          latest              d1fd7d86a825        4 months ago        33.3 MB
docker.io/training/webapp   latest              6fae60ef3446        2 years ago         349 MB

比如要push镜像docker.io/registry

2. tag镜像为私有仓库ip:port,不打tag,push不知道目标ip和端口

[root@c1awn01 ~]# docker tag docker.io/registry 192.168.80.129:5000/local_registry
[root@c1awn01 ~]# docker images
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
nginx                                latest              f1280371d1cb        17 hours ago        109 MB
test_nginx                           latest              8947401b76ed        18 hours ago        109 MB
centos/zip                           latest              c7ce05084477        3 days ago          302 MB
docker.io/nginx                      latest              ae513a47849c        12 days ago         109 MB
docker.io/centos                     latest              e934aafc2206        5 weeks ago         199 MB
192.168.80.129:5000/local_registry   latest              d1fd7d86a825        4 months ago        33.3 MB
docker.io/registry                   latest              d1fd7d86a825        4 months ago        33.3 MB
docker.io/training/webapp            latest              6fae60ef3446        2 years ago         349 MB

此时已经多了一个tag为私有仓库的镜像

3. push

[root@c1awn01 ~]# docker push 192.168.80.129:5000/local_registry
The push refers to a repository [192.168.80.129:5000/local_registry]
Get https://192.168.80.129:5000/v1/_ping: http: server gave HTTP response to HTTPS client

push报错,提示我们用HTTPS

4. 修改push的HTTPS要求

[root@c1awn01 ~]# vi /etc/docker//daemon.json

{
    "registry-mirrors": [
        "http://9686e306.m.daocloud.io"
    ],
    "insecure-registries": [ "192.168.80.129:5000" ]
}

/etc/docker//daemon.json加入 "insecure-registries": [ "192.168.80.129:5000" ],前面在线仓库的加速地址因人而异

5. 重启docker,再次push

[root@c1awn01 ~]# systemctl restart docker
[root@c1awn01 ~]# docker run -d -p 5000:5000 docker.io/registry 
63c148557f3e8517a1da4cedae18f52f8b644cf1b583ae083c1e8d9fd15e5f54
[root@c1awn01 ~]# docker push 192.168.80.129:5000/local_registry
The push refers to a repository [192.168.80.129:5000/local_registry]
9113493eaae1: Pushed 
621c2399d41a: Pushed 
59e80739ed3f: Pushed 
febf19f93653: Pushed 
e53f74215d12: Pushed 
latest: digest: sha256:feb40d14cd33e646b9985e2d6754ed66616fedb840226c4d917ef53d616dcd6c size: 1364

curl私有仓库地址查看镜像

[root@c1awn01 ~]# curl 127.0.0.1:5000/v2/_catalog
{"repositories":["local_registry"]}

现在中括号里多了一个local_registry镜像

转载于:https://my.oschina.net/u/3746745/blog/1811532

最后

以上就是真实乌龟为你收集整理的docker搭建局域网私有仓库1. 环境2. docker pull registry 拉取官方仓库镜像3. 用刚拉取的镜像启动容器4. 查看本地仓库curl 127.0.0.1:5000/v2/_catalog5. push本地镜像到私有仓库的全部内容,希望文章能够帮你解决docker搭建局域网私有仓库1. 环境2. docker pull registry 拉取官方仓库镜像3. 用刚拉取的镜像启动容器4. 查看本地仓库curl 127.0.0.1:5000/v2/_catalog5. push本地镜像到私有仓库所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(33)

评论列表共有 0 条评论

立即
投稿
返回
顶部