Docker Base Image 创建
本着学习的态度,想了解创建 Docker Base Image的方法,在官网,在百度,在相关论坛,查找相关资料,这里记录下实现的步骤,
一. 环境
宿主机操作系统: OS X ,需要安装VirtualBox ;
容器环境:centos7二. 用VirtualBox 安装系统,这里以centos 7为例(CentOS-7-x86_64-Minimal-1503-01.iso)
创建虚拟机,并安装centos7,以下记录了详细安装过程。
* 安装过程简单,我这里网速太慢了,就不上图了,有需要的朋友留个邮箱,我发pdf。*
安装完后,重启后进入系统。
三. 修改网络配置
修改网络配置 /etc/sysconfig/network-script/ifcfg-enp0s3。删除 UUID,HWADDR ;修改ONBOOT=no 为 ONBOOT=yes , 然后保存 。$ ifconfig Cannot find a valid baseurl for repo: base/7/x86_6重启网络接口:[root@centos7 ~]#ifdown enps03[root@centos7 ~]#ifup enps03$ yum install ifconfig 提示:Nothing to do 通过” yum provides” 命令列出那个包提供ifconfig命令$ yum provides ifconfig // 安装$ yum -y install net-tools
四. 安装Docker
安装 EPEL (参考:http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/ )[root@centos7 ~]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm修改/etc/yum.repos.d/CentOS-Base.repo 把enabled=0 改成enabled=1vim /etc/yum.repos.d/CentOS-Base.repo[centosplus]enabled=1安装 Docker[root@centos7 yum.repos.d]# yum install docker-io启动 Docker [root@centos7 yum.repos.d]# service docker start
五. 创建基础镜像
替换变量把 /etc/yum.repos.d/CentOS-Base.repo 文件中$releasever 替换成 7$basearch 替换成 x86_64快速替换方法:vim /etc/yum.repos.d/CentOS-Base.repo:%s/$releasever/7/g:%s/$basearch/x86_64/g创建Docker image 生成脚本[root@centos7 yum.repos.d]# cd /root[root@centos7 ~]# mkdir scripts[root@centos7 ~]# cd scripts/[root@centos7 scripts]# vim createimage.sh然后把 https://github.com/docker/docker/blob/master/contrib/mkimage-yum.sh 文件中内容粘贴进去[root@centos7 scripts]# chmod +x createimage.sh创建image[root@centos7 scripts]# ./createimage.sh centos7base创建成功后查看,并把当前运行的容器删除掉[root@centos7 tmp]# docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEcentos7base 7.1.1503 112ee00c2cbc 8 minutes ago 227.7 MB[root@centos7 tmp]# docker ps -allCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES752b9d49a079 centos7base:7.1.1503 "echo success" 10 minutes ago Exited (0) 10 minutes ago mad_saha[root@centos7 tmp]# docker rm 752b9d49a079752b9d49a079[root@centos7 tmp]# docker ps -allCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES导出image[root@centos7 tmp]# cd /tmp/[root@centos7 tmp]# docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEcentos7base 7.1.1503 112ee00c2cbc 14 minutes ago 227.7 MB[root@centos7 tmp]# docker save 112ee00c2cbc > /tmp/centos7base.tar[root@centos7 tmp]# lscentos7base.tar ks-script-L8TDO5 yum.log[root@centos7 tmp]#
新闻热点
疑难解答