docker对镜像的相关操作
一、创建镜像在现有镜像的基础上启动一个容器
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos centos7 7322fbe74aa5 6 days ago 172.2 MB
centos centos6.6 8b44529354f3 9 weeks ago 202.6 MB
# docker run -t -i centos:centos6.6 /bin/bash
# hostname
06ba542f19c9 #这个是容器ID,唯一值 在容器中添加一个httpd服务
# rpm -qa|grep httpd
# yum install httpd -y
# rpm -qa |grep httpd
httpd-tools-2.2.15-39.el6.centos.x86_64
httpd-2.2.15-39.el6.centos.x86_64
# exit
exit 在我们使用exit退出后,容器已经被我们改变了,使用docker commit来提交新的信息
# docker commit -m "add httpd" -a "root" 06ba542f19c9 centos:centos6.6_v1
ae2ffc5dbfcc7944a624c55bc081b9514c83b420450d1ea9c67afc0b677bd686
#-m 来指定提交的说明信息
#-a 可以指定更新的用户信息
#06ba542f19c9 这是我们上面启动容器后生成的ID
#centos:centos6.6_v1 前面的一部分表示那个repo,后面的一部分表示TAG
#查看提交后的结果
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos centos6.6_v1 ae2ffc5dbfcc 9 seconds ago 274.2 MB
centos centos7 7322fbe74aa5 6 days ago 172.2 MB
centos centos6.6 8b44529354f3 9 weeks ago 202.6 MB 我们使用新创建的镜像来启动容器
# docker run -t -i centos:centos6.6_v1 /bin/bash
# hostname
5fc242e53248
# rpm -qa |grep httpd #在前面添加的httpd也存在
httpd-tools-2.2.15-39.el6.centos.x86_64
httpd-2.2.15-39.el6.centos.x86_64 在上面的例子中我们是使用的docker commit来创建的镜像,下面我们使用dockerfile来创建镜像
# mkdir git
# cd git
# cat Dockerfile
FROM centos:centos6.6 #已哪个镜像作为基础
MAINTAINER lyao #维护者的信息
RUN yum install git-y #要安装的软件包
# docker build -t "git" . #-t 添加注释
#查看结果
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
#新添加的镜像
git latest 8aa77ab9e593 6 minutes ago 301.1 MB
centos centos6.6_v1 ae2ffc5dbfcc 4 days ago 274.2 MB
centos centos7 7322fbe74aa5 11 days ago 172.2 MB
centos centos6.6 8b44529354f3 9 weeks ago 202.6 MB
页:
[1]