我创建了名为“task1”的docker容器。
我执行一个shell命令,它创建一个包含单词“hello”的文件foo.txt。
我提交了docker容器“task1”
我使用-it命令
以交互模式进入docker容器“task1”但是我没有看到文件“foo.txt”。我期待它,因为我已经提交了容器。 但是,当我只传递“ls”命令并在同一容器“task1”中执行它时,它会显示文件“foo.txt”。
这是什么问题?以下是我正在尝试上述活动的控制台细节。感谢您的帮助。感谢。
~/G/S/d/d/H/test_io master ± docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
35784a56ffa3 task1 "/bin/bash" 5 seconds ago Up 4 seconds task2
eb03c7b89e36 task1 "/bin/bash" 6 minutes ago Up 6 minutes clever_bell
352c6f8f1ff2 registry:2 "/bin/registry /etc/d" 10 days ago Up About an hour 0.0.0.0:5000->5000/tcp registry
~/G/S/d/d/H/test_io master ± docker exec -it eb03c7b89e36 script /dev/null -c "echo 'Hello' > foo.txt"
Script started, file is /dev/null
Script done, file is /dev/null
~/G/S/d/d/H/test_io master ± docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
35784a56ffa3 task1 "/bin/bash" 2 minutes ago Up 2 minutes task2
eb03c7b89e36 task1 "/bin/bash" 8 minutes ago Up 8 minutes clever_bell
352c6f8f1ff2 registry:2 "/bin/registry /etc/d" 10 days ago Up About an hour 0.0.0.0:5000->5000/tcp registry
~/G/S/d/d/H/test_io master ± docker commit eb03c7b89e36
6d8666dc72caa36f436c46fe65e5beb6a1421ea27867153658303e430a33f126
~/G/S/d/d/H/test_io master ± docker run -it task1
root@aad8db09c5fe:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@aad8db09c5fe:/# exit
exit
~/G/S/d/d/H/test_io master ± docker exec -it eb03c7b89e36 ls
bin dev foo.txt lib media opt root sbin sys usr
boot etc home lib64 mnt proc run srv tmp var
~/G/S/d/d/H/test_io master ± docker start clever_bell
clever_bell
~/G/S/d/d/H/test_io master ± docker run -it task1
root@4bfba10c7c49:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@4bfba10c7c49:/# exit
exit
答案 0 :(得分:3)
docker commit <container>
不会以任何方式改变容器的图像;它只是创建一个与原始图像分开的 new 图像。如果您希望更新test1
图片,则需要为新图片指定名称:docker commit <container> test1
。