docker搭建局域网私有仓库

如无特殊说明,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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值