一、docker container commit
1、交互式运行容器
[docker@localhost ~]$ docker run -it centos
2、进行修改
[docker@localhost ~]$ docker run -it centos
[root@3665e1d73dae /]# yum install -y vim
3、commit成新的Image
[docker@localhost ~]$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3665e1d73dae centos "/bin/bash" 9 minutes ago Exited (0) 20 seconds ago object
ive_pasteur
[docker@localhost ~]$ docker commit 3665e1d73dae zheng007/centos_vim
sha256:b0da2f0488caa68c5977f662fa145dd3f41be4105337a78380572536658e97a2
[docker@localhost ~]$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
zheng007/centos_vim latest b0da2f0488ca 57 seconds ago 335MB
centos latest 1e1148e4cc2c 2 months ago 202MB
到此就完成了新image创建,docker history [image ID]
此方式不提倡,因为不能透明所做的修改操作,存在安全风险
二、docker image build
1、创建Dockerfile并编辑
FROM centos
RUN yum install -y vim
2、build
docker build -t [new Base Image name] . #当前目录