一、commit封装镜像
我们以ubuntu的镜像为例:
首先有ubentu的镜像
[root@server1 ~]# docker images ubuntu
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 07c86167cdc4 3 years ago 188MB
我们先建立vm1容器,然后对其进行一些操作,然后ctrl+p+q退出
[root@server1 ~]# docker run -it --name vm1 ubuntu
root@6074aca22100:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@6074aca22100:/# touch file{1..10}
root@6074aca22100:/# ls
bin etc file2 file5 file8 lib mnt root srv usr
boot file1 file3 file6 file9 lib64 opt run sys var
dev file10 file4 file7 home media proc sbin tmp
在上面的基础上我们删除vm1容器,然后重新建立,查看建立的文件是否还存在
[root@server1 ~]# docker rm -f vm1
vm1
[root@server1 ~]# docker run -it --name vm1 ubuntu
root@94a7b7a6ffc0:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
我们可以发现我们创建的文件没有了,我们的操作没有被保存。
那么我们如果需要让其继续存在就需要重新建立,然后重新commit封装即可
root@94a7b7a6ffc0:/# touch file{1..10}
root@94a7b7a6ffc0:/# ls
bin etc file2 file5 file8 lib mnt root srv usr
boot file1 file3 file6 file9 lib64 opt run sys var
dev file10 file4 file7 home media proc sbin tmp
ctrl+d释放资源退出,封装镜像
root@94a7b7a6ffc0:/# exit
[root@server1 ~]# docker commit -m "add files" vm1 ubuntu:v1
sha256:387e3d445215ca2e177b4c8f0ae3807edffd919a13be237ebcc5e69c4f1523b8