【Docker】本地镜像发布到私有库

推送过程

下载registry镜像

命令:

docker pull registry

[root@192 ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
79e9f2f55bf5: Pull complete 
0d96da54f60b: Pull complete 
5b27040df4a2: Pull complete 
e2ead8259a04: Pull complete 
3790aef225b9: Pull complete 
Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@192 ~]# docker images
REPOSITORY                                                  TAG       IMAGE ID       CREATED             SIZE
registry.cn-hangzhou.aliyuncs.com/kuangdi1992/myubuntu1.1   1.1       dac744a2b764   About an hour ago   183MB
registry                                                    latest    b8604a3fe854   16 months ago       26.2MB
ubuntu                                                      latest    ba6acccedd29   17 months ago       72.8MB
redis                                                       6.0.8     16ecd2772934   2 years ago         104MB

运行私有库registry

命令:

docker run -d -p 5000:5000 -v /zzyyuse/myregistry/:/tmp/registry --privileged=true registry

[root@192 ~]# docker run -d -p 5000:5000 -v /zzyyuse/myregistry/:/tmp/registry --privileged=true registry
9ba894c810614235890f7cb1b6a194afb7766cb6bfed91a5e89a64517cde7465
[root@192 ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED         STATUS         PORTS                                       NAMES
9ba894c81061   registry   "/entrypoint.sh /etc…"   5 seconds ago   Up 4 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   sharp_chatterjee

生成自己的镜像

用docker commit命令生成新的镜像。

[root@192 ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED         STATUS         PORTS                                       NAMES
49016c76073e   ubuntu     "/bin/bash"              3 minutes ago   Up 3 minutes                                               angry_nightingale
9ba894c81061   registry   "/entrypoint.sh /etc…"   41 hours ago    Up 41 hours    0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   sharp_chatterjee
[root@192 ~]# docker commit -m="add ifconfig" -a="kd" 49016c76073e kd/myubuntu:1.2
sha256:9582a943a6b6eb9f5663ff8517cc59343c03ec830ceb902e17128209ab58d380
[root@192 ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED          SIZE
kd/myubuntu   1.2       9582a943a6b6   10 seconds ago   116MB
registry      latest    b8604a3fe854   17 months ago    26.2MB
ubuntu        latest    ba6acccedd29   17 months ago    72.8MB
redis         6.0.8     16ecd2772934   2 years ago      104MB

curl验证私服库上有什么镜像

命令:

curl -XGET http://192.168.12.130:5000/v2/_catalog ip为本地ip

[root@192 ~]# curl -XGET http://192.168.12.130:5000/v2/_catalog
{"repositories":[]}

将新镜像修改符合私服规范的TAG

命令:

docker tag 镜像:TAG Host:Port/Repository:Tag

[root@192 ~]# docker tag kd/myubuntu:1.2 192.168.12.130:5000/kdubuntu:1.2
[root@192 ~]# docker images
REPOSITORY                     TAG       IMAGE ID       CREATED         SIZE
192.168.12.130:5000/kdubuntu   1.2       9582a943a6b6   9 minutes ago   116MB
kd/myubuntu                    1.2       9582a943a6b6   9 minutes ago   116MB
registry                       latest    b8604a3fe854   17 months ago   26.2MB
ubuntu                         latest    ba6acccedd29   17 months ago   72.8MB
redis                          6.0.8     16ecd2772934   2 years ago     104MB

修改配置文件使支持http

文件:/etc/docker/daemon.json

[root@192 ~]# cat /etc/docker/daemon.json 
{

"registry-mirrors": ["https://pylcjgsv.mirror.aliyuncs.com"],
"dns" : [
    "8.8.8.8"
  ],
"insecure-registries":["192.168.12.130:5000"]

}

修改完成后,如果不生效的话,建议重启docker。

重启后,重新运行私服仓库。

push推送到私服库,并验证

命令:

docker push 192.168.12.130:5000/kdubuntu:1.2

[root@192 ~]# docker images
REPOSITORY                     TAG       IMAGE ID       CREATED          SIZE
192.168.12.130:5000/kdubuntu   1.2       9582a943a6b6   15 minutes ago   116MB
kd/myubuntu                    1.2       9582a943a6b6   15 minutes ago   116MB
registry                       latest    b8604a3fe854   17 months ago    26.2MB
ubuntu                         latest    ba6acccedd29   17 months ago    72.8MB
redis                          6.0.8     16ecd2772934   2 years ago      104MB
[root@192 ~]# docker push 192.168.12.130:5000/kdubuntu:1.2
The push refers to repository [192.168.12.130:5000/kdubuntu]
ec2f99c36fde: Pushed 
9f54eef41275: Pushed 
1.2: digest: sha256:263cfea88b58d3f3d01e3e407edbf2ce869e109e394a826d7603e833850fd8ae size: 741
[root@192 ~]# curl -XGET http://192.168.12.130:5000/v2/_catalog
{"repositories":["kdubuntu"]}

pull到本地并运行

命令:

docker pull 192.168.12.130:5000/kdubuntu:1.2

[root@192 ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED          SIZE
kd/myubuntu   1.2       9582a943a6b6   17 minutes ago   116MB
registry      latest    b8604a3fe854   17 months ago    26.2MB
ubuntu        latest    ba6acccedd29   17 months ago    72.8MB
redis         6.0.8     16ecd2772934   2 years ago      104MB
[root@192 ~]# curl -XGET http://192.168.12.130:5000/v2/_catalog
{"repositories":["kdubuntu"]}
[root@192 ~]# docker pull 192.168.12.130:5000/kdubuntu:1.2
1.2: Pulling from kdubuntu
Digest: sha256:263cfea88b58d3f3d01e3e407edbf2ce869e109e394a826d7603e833850fd8ae
Status: Downloaded newer image for 192.168.12.130:5000/kdubuntu:1.2
192.168.12.130:5000/kdubuntu:1.2
[root@192 ~]# docker images
REPOSITORY                     TAG       IMAGE ID       CREATED          SIZE
192.168.12.130:5000/kdubuntu   1.2       9582a943a6b6   19 minutes ago   116MB
kd/myubuntu                    1.2       9582a943a6b6   19 minutes ago   116MB
registry                       latest    b8604a3fe854   17 months ago    26.2MB
ubuntu                         latest    ba6acccedd29   17 months ago    72.8MB
redis                          6.0.8     16ecd2772934   2 years ago      104MB
[root@192 ~]# docker run -it 9582a943a6b6 /bin/bash
root@d44f9886fd80:/# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.3  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:03  txqueuelen 0  (Ethernet)
        RX packets 6  bytes 516 (516.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

你可能感兴趣的:(docker,linux,运维)