docker镜像库

镜像库

1.官方镜像库
2.道客云镜像库(国内比较快)

私有镜像库

配置私有镜像库

1、下载仓库镜像
docker pull registry
2、运行仓库镜像
docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry:latest
3、配置daemon.json
vi /etc/docker/daemon.json
里面的内容是一个json对象,加上一项insecure-registries,地址自己更改:
{
"insecure-registries":["192.168.218.130:5000"]
}
然后重启docker,执行
systemctl daemon-reload && systemctl restart docker.service
4、查看docker镜像库
curl http://192.168.218.130:5000/v2/_catalog
5、测试上传到我们自己的私有registry
docker tag nginx 192.168.218.130:5000/mynginx
docker push 192.168.218.130:5000/mynginx
6、可能出现的问题

没有禁用selinux,将selinux禁用后就可以push了

7、配置host
vi /etc/hosts
在后面新添一行
127.0.0.1 docker.example.com

将镜像推送至私有镜像库

1.打标签
docker tag aa5364eb3d85 docker.example.com:5000/docker.io/mysql

2.推送到新的Registry
docker push docker.example.com:5000/docker.io/mysql

用python脚本查看私有镜像库

1、首先安装epel扩展源:
  yum -y install epel-release
  更新完成之后,就可安装pip:
  yum -y install python-pip
  安装完成之后清除cache:
  yum clean all
2、request模块安装:
pip install request

3、vi get.py,并写入以下内容
#!/usr/bin/env python
#-*- coding:utf-8 -*-

import requests  
import json  
import traceback  
   
repo_ip = '192.168.239.100'  
repo_port = 4000  
   
def getImagesNames(repo_ip,repo_port):  
    docker_images = []  
    try:  
        url = "http://" + repo_ip + ":" +str(repo_port) + "/v2/_catalog"  
        res =requests.get(url).content.strip()  
        res_dic = json.loads(res)  
        images_type = res_dic['repositories']  
        for i in images_type:  
            url2 = "http://" + repo_ip + ":" +str(repo_port) +"/v2/" + str(i) + "/tags/list"  
            res2 =requests.get(url2).content.strip()  
            res_dic2 = json.loads(res2)  
            name = res_dic2['name']  
            tags = res_dic2['tags']  
            for tag in tags:  
                docker_name = str(repo_ip) + ":" + str(repo_port) + "/" + name + ":" + tag  
                docker_images.append(docker_name)  
                print docker_name  
    except:  
        traceback.print_exc()  
    return docker_images  
   
a=getImagesNames(repo_ip, repo_port)  
#print a  

4、 运行脚本
python get.py

通过脚本将镜像推送到仓库

1、vi /opt/shell/push-private-registry
2、文件内容
#!/bin/bash

private_registry_host='192.168.239.100'
private_registry_port='4000'
openstack_images_array=($(docker images | egrep -v "${private_registry_host}" | awk '{if(NR>1){print $1}}'))
unset openstack_images_array[${#openstack_images_array[*]}-1]

${openstack_images_array[${#openstack_images_array[*]}-1]}
openstack_images_tag='ocata'

for image in ${openstack_images_array[@]}
do
    docker tag ${image}:${openstack_images_tag} ${private_registry_host}:${private_registry_port}/${image}:${openstack_images_tag}
    docker push ${private_registry_host}:${private_registry_port}/${image}:${openstack_images_tag}
    docker rmi ${private_registry_host}:${private_registry_port}/${image}:${openstack_images_tag}
done

3、命令
chmod +x /opt/shell/push-private-registry
./push-private-registry

导入导出镜像

一、导出
1、使用docker images查看本机所有的镜像文件
2、docker save eb40dcf64078> /root/mydjango-save-1016.tar  将镜像保存为本地文件,其中eb40dcf64078为image id

二、导入
1、使用load方法加载刚才上传的tar文件
docker load < /root/mydjango-save-1016.tar
2、在新的机器上再此使用docker images命令查看本机的镜像,检查刚才load的镜像有没有加载进来,发现加载进来的镜像名称、标签均为none,使用docker tag eb40dcf64078 django:latest 修改为原来的镜像名称和标签名称,其中eb40dcf64078 为images id
3、使用docker run -itd django:latest加载进行,验证镜像是否能够成功的“run”
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值