Docker Base Image自己创建具体实现
宿主机操作系统: os x ,需要安装virtualbox ;
容器环境:centos7
二. 用virtualbox 安装系统,这里以centos 7为例(centos-7-x86_64-minimal-1503-01.iso)
创建虚拟机,并安装centos7,以下记录了详细安装过程。


* 安装过程简单,我这里网速太慢了,就不上图了,有需要的朋友留个邮箱,我发pdf。*
安装完后,重启后进入系统。
三. 修改网络配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
修改网络配置 /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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
安装 epel (参考:http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/ )
[root@centos7 ~]# rpm -uvh
修改/etc/yum.repos.d/centos-base.repo 把enabled=0 改成enabled=1
vim /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
五. 创建基础镜像
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
替换变量
把 /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 images
repository tag image id created virtual size
centos7base 7.1.1503 112ee00c2cbc 8 minutes ago 227.7 mb
[root@centos7 tmp]# docker ps -all
container id image command created status ports names
752b9d49a079 centos7base:7.1.1503 "echo success" 10 minutes ago exited (0) 10 minutes ago mad_saha
[root@centos7 tmp]# docker rm 752b9d49a079
752b9d49a079
[root@centos7 tmp]# docker ps -all
container id image command created status ports names
导出image
[root@centos7 tmp]# cd /tmp/
[root@centos7 tmp]# docker images
repository tag image id created virtual size
centos7base 7.1.1503 112ee00c2cbc 14 minutes ago 227.7 mb
[root@centos7 tmp]# docker save 112ee00c2cbc > /tmp/centos7base.tar
[root@centos7 tmp]# ls
centos7base.tar ks-script-l8tdo5 yum.log
[root@centos7 tmp]#
六. docker 常用命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
docker stop <container id> :用来停止运行中的容器,同时你还可以用
docker start <container id>:用来启动一个已经停止的容器。
docker restart <container id>:可以重启一个运行中的容器。这就相当于对一个容器先进行stop再start。
docker attach <container id> :关联到一个正在运行的容器
删除镜像: docker rmi <image id>
docker rmi 2db1e85f26ba
删除容器:docker rm <container id>
docker rm c3bfb652a491
查看正在运行的容器
docker ps -all
停止容器:
exit
重新进入窗口
docker start <container id>
docker attach <container id>
暂时退出容器
ctrl + p 然后 ctrl + q
重新入进:
docker attach <container id>
将容器保存成镜像:
docker commit <container id> <name>:<tag>
七. 导到本地镜像库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
回去宿主机,把虚拟机中导出的image拷到本地
hr:~ hr$ mkdir -p docker/images
hr:~ hr$ cd docker/images/
hr:images hr$ scp [email protected]:/tmp/centos7base.tar .
hr:images hr$ ls -lah
total 469392
drwxr-xr-x 3 hr staff 102b 12 5 21:08 .
drwxr-xr-x 3 hr staff 102b 12 5 21:05 ..
-rw-r--r-- 1 hr staff 229m 12 5 21:08 centos7base.tar
启动docker quick start terminal
加载image 包到docker image
hr:images hr$ docker load < /users/hr/docker/images/centos7base.tar
hr:images hr$ docker images
repository tag image id created virtual size
<none> <none> 112ee00c2cbc 29 minutes ago 227.7 mb
hello-world latest 975b84d108f1 7 weeks ago 960 b
tar 等于none的就是刚刚导入的,把tag改个名字:
hr:images hr$ docker tag 112ee00c2cbc centos7base:7.1
hr:images hr$ docker images
repository tag image id created virtual size
centos7base 7.1 112ee00c2cbc 33 minutes ago 227.7 mb
hello-world latest 975b84d108f1 7 weeks ago 960 b
运行容器:
hr:images hr$ docker run -i -t 112ee00c2cbc /bin/bash
[root@e948acae7b42 /]# hostname
e948acae7b42
[root@e948acae7b42 /]# cat /etc/redhat-release
centos linux release 7.1.1503 (core)
八. 发布镜像到docker hub
前提是先注册一个帐号:https://hub.docker.com/
1. 登录
docker login —username=<用户名> —email=<邮箱地址>
2. 按docker repository 要求修改镜像tag
docker tag <image id> 用户名/镜像名/tag
docker tag 112ee00c2cbc honor/centos7base:7.1
3. 上传
docker push honor/centos7base
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/server/other/7689.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
卸载后云锁网站无法会见
时间:2021-01-23
-
处事器安详软件云锁“及
时间:2021-01-23
-
CentOS 7安装Docker处事具体进
时间:2021-01-16
-
下一步: 选第一个
时间:2021-01-16
-
分区方案选择标准分区
时间:2021-01-16
-
VMware给虚拟机安装linux系统
时间:2021-01-16
-
安全软件不仅可以保护I
时间:2021-01-13
-
宝塔防火墙种种利害名单
时间:2021-01-13
热门文章
-
VirtualBox简体中文版下载安装(图解教程)
时间:2020-12-23
-
电商平台为什么要使用独立服务器托管?
时间:2020-12-22
-
基于Kubernetes和Docker实现留言簿案例
时间:2021-01-06
-
在virtualbox中安装CentOS7图文教程
时间:2020-12-22
-
网络安全之PKI技术原理
时间:2020-12-23
-
常见的云安全错误认知以及应对方法!
时间:2020-12-26
-
Docker Base Image自己创建具体实现
时间:2020-12-22
-
Windows系统中安装云锁服务器端的图文教程
时间:2020-12-25
-
VMware给虚拟机安装linux系统
时间:2021-01-16
-
云服务器/VPS/云主机/服务器修改登陆密码
时间:2020-12-22
