docker使用现有容器生成新的镜像

/*运行docker run后 --则进入该容器里了 

            我们做一些变更,比如安装一些东西 ,然后针对这个容器进行创建新的镜像
*/

基本形式:

docker commit -m "change somth" -a "somebody info" container_id(docker ps -a获取id) 新镜像名字

eg.
Ian 
docker commit -m "install httpd" -a   ”frank  ie" 2c74d574293f frankie/centos  
  
/* 意义就是 为某一个功能,创建一个镜像    */

docker exec -it de8[id的简写] /bin/bash    --进入容器
/*
实例:
进入容器后,ifconfig ,wget等命令都不存在 可以利用yum进行安装 */ [root@64b1a3401832 /]# yum install -y net-tools wget //查看此容器的版本 [root@64b1a3401832 /]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@64b1a3401832 /]# uname -a Linux 64b1a3401832 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux //然后对刚刚的容器进行新创建,要回到原来的shell里 [root@localhost ~]# docker commit -m "centos_with_nettools_and_wget" -a "Frankie(作者名)" 64b centos_with_net c5b412fe1c33f5dd98030c5ed22503b255eca0aac21175e7312465db4cb595cf [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos_with_net latest c5b412fe1c33 27 seconds ago 294.1 MB centos latest d83a55af4e75 4 weeks ago 196.7 MB frankie latest d83a55af4e75 4 weeks ago 196.7 MB [root@localhost ~]# /* 此时创建的镜像里 , 有ifconfig 和 wget两个功能 ,可以连接网络 */

 

posted @ 2016-08-29 14:43  Frankiee  阅读(28484)  评论(0编辑  收藏  举报