【docker】新镜像推送到私服库配置

目录

工作环境:

一、下载镜像Docker  Register

二、运行私有库Register

三、创建一个新镜像

四、验证私服库有什么镜像

五、修改新镜像符合规范的tag

六、修改配置文件使之支持http

七、推送到私服库

八、再次验证私服库有什么镜像

九、拉取到本地运行


工作环境:

        主机IP地址为192.168.10.129

一、下载镜像Docker  Register

[root@k8s-master ~]# docker pull registry

docker images命令检查一下

二、运行私有库Register

        相当于本地有个私有Docker Hub

[root@k8s-master ~]# docker run -d -p 5000:5000 -v ~/myregistry:/tmp/registry --privileged=true registry
[root@k8s-master ~]# docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS         PORTS                                       NAMES
96f589d121a3   registry                 "/entrypoint.sh /etc…"   10 seconds ago   Up 9 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   recursing_hamilton

三、创建一个新镜像

#比如说创建一个新镜像,先拉取ubuntu镜像,在此镜像基础上再创建一个新的镜像
[root@k8s-master ~]# docker pull ubuntu        #运行ubuntu
[root@k8s-master ~]# docker run -it ubuntu /bin/bash  

root@40adfece4876:/# vim a      
bash: vim: command not found  
root@40adfece4876:/# ifconfig  
bash: ifconfig: command not found         #此时并没有vim和ifconfig命令 
 
root@40adfece4876:/# apt-get update       #更新一下
root@40adfece4876:/# apt-get install vim        #安装
root@40adfece4876:/# apt-get install net-tools    #现在拥有了vim和ifconfig命令

   #开始创建

[root@k8s-master /]# docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED          STATUS          PORTS                                       NAMES
40adfece4876   ubuntu                   "/bin/bash"              12 minutes ago   Up 12 minutes                                               relaxed_engelbart
96f589d121a3   registry                 "/entrypoint.sh /etc…"   17 minutes ago   Up 17 minutes   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   recursing_hamilton
#m代表描述,a代表作者,后面是ubuntu容器id,容器名:标签名
[root@k8s-master ~]# docker commit -m="ifconfig and vim" -a="weiyun" 40adfece4876 weiyunubuntu:1.2
[root@k8s-master ~]# docker images
REPOSITORY                                       TAG        IMAGE ID       CREATED         SIZE
weiyunubuntu                                     1.2        7523b4480729   2 minutes ago   180MB
registry                                         latest     b8604a3fe854   10 months ago   26.2MB
ubuntu                                           latest     ba6acccedd29   11 months ago   72.8MB

#验证 

#停止Ubuntu容器
[root@k8s-master ~]# docker stop 40adfece4876 
#启用weiyunUbuntu
[root@k8s-master ~]# docker run -it 7523b4480729 /bin/bash
root@87926f3352a8:/# ifconfig 
eth0: flags=4163  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 43  bytes 7624 (7.6 KB)
        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  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

四、验证私服库有什么镜像

[root@k8s-node1 ~]# curl -XGET http://192.168.10.129:5000/v2/_catalog
{"repositories":[]}    #空的,什么都没有

五、修改新镜像符合规范的tag

[root@k8s-master ~]# docker tag weiyunubuntu:1.2 192.168.10.129:5000/weiyunbuntu:1.2
[root@k8s-master ~]# docker images
REPOSITORY                                       TAG        IMAGE ID       CREATED          SIZE
192.168.10.129:5000/weiyunbuntu                  1.2        7523b4480729   52 minutes ago   180MB
weiyunubuntu                                     1.2        7523b4480729   52 minutes ago   180MB
registry                                         latest     b8604a3fe854   10 months ago    26.2MB
ubuntu                                           latest     ba6acccedd29   11 months ago    72.8MB
#相当于克隆了一份weiyunubuntu:1.2 

六、修改配置文件使之支持http

[root@k8s-master ~]# vim /etc/docker/daemon.json
{
    "registry-mirrors": ["https://8zs3633v.mirror.aliyuncs.com"],    #加速器
    "insecure-registries":["192.168.10.129:5000"]
}
#docker默认不允许http方式推送镜像,通过配置选项来取消这个限制。修改完后如果不生效,建议重启docker
[root@k8s-master ~]# systemctl restart docker
[root@k8s-master ~]# docker run -d -p 5000:5000 -v ~/myregistry:/tmp/registry --privileged=true registry

七、推送到私服库
 

[root@k8s-master ~]# docker push 192.168.10.129:5000/weiyunbuntu:1.2

八、再次验证私服库有什么镜像

[root@k8s-master ~]# curl -XGET http://192.168.10.129:5000/v2/_catalog
{"repositories":["weiyunbuntu"]}

九、拉取到本地运行

#先删除本地的镜像
[root@k8s-master ~]# docker rmi 192.168.10.129:5000/weiyunbuntu:1.2
[root@k8s-master ~]# docker rmi -f weiyunubuntu:1.2
#拉取
[root@k8s-master ~]# docker pull 192.168.10.129:5000/weiyunbuntu:1.2
[root@k8s-master ~]# docker images
REPOSITORY                                       TAG        IMAGE ID       CREATED             SIZE
192.168.10.129:5000/weiyunbuntu                  1.2        7523b4480729   About an hour ago   180MB
registry                                         latest     b8604a3fe854   10 months ago       26.2MB
ubuntu                                           latest     ba6acccedd29   11 months ago       72.8MB
[root@k8s-master ~]# docker run -it 7523b4480729 /bin/bash
root@fbf0539bf4e4:/# ifconfig
eth0: flags=4163  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 15  bytes 2070 (2.0 KB)
        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  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,docker,容器,linux,运维,centos)