码迷,mamicode.com
首页 > 其他好文 > 详细

Docker镜像制作

时间:2018-05-06 14:59:53      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:hello   created   home   back   star   create   efi   ima   roo   

方法1:docker commit

jiqing@ThinkPad:~$ sudo docker commit 1949036422c3 centos:jiqing
[sudo] password for jiqing: 
sha256:4be35dd8f7b4c975c4cf1d35414147ef4dfadbb7a6e1a11f21cebee1ff12428e
jiqing@ThinkPad:~$ sudo docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
centos                            jiqing              4be35dd8f7b4        11 seconds ago      1.36GB
hello-world                       latest              e38bc07ac18e        3 weeks ago         1.85kB
imagine10255/centos6-lnmp-php56   latest              ecc74d703eca        18 months ago       1.31GB
jiqing@ThinkPad:~$ sudo docker run -it centos:jiqing
Starting nginx:                                            [  OK  ]
Starting php-fpm:                                          [  OK  ]
Starting sshd:                                             [  OK  ]
[root@c10a4c3541f5 home]# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:AC:11:00:02  
          inet addr:172.17.0.2  Bcast:172.17.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:45 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:6345 (6.1 KiB)  TX bytes:0 (0.0 b)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

方法二:docker build

jiqing@ThinkPad:~$ sudo mkdir /docker-build
jiqing@ThinkPad:~$ cd /docker-build/
jiqing@ThinkPad:/docker-build$ sudo touch Dockerfile

注,make自动化编译需要Makefile,自动化docker镜像需要Dockerfile

FROM centos
MAINTAINER jiqing <jiqing9006@126.com>
RUN yum -y install httpd
ADD start.sh /usr/local/bin/start.sh
ADD index.html /var/www/html/index.html

创建start.sh并设置为可执行

echo "/usr/sbin/httpd -DFOREGROUND" >  start.sh
chmod a+x start.sh 

创建index.html

echo "docker image build test" > index.html

自定义创建对象

 sudo docker build -t centos:httpd /docker-build

启动镜像

sudo docker run -it centos:httpd

开启http服务

start.sh

查看结果

技术分享图片

Docker镜像制作

标签:hello   created   home   back   star   create   efi   ima   roo   

原文地址:https://www.cnblogs.com/jiqing9006/p/8997942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!