docker python:在容器中提交更改,但新映像不运行
我有一个名为docker python:在容器中提交更改,但新映像不运行,python,docker,Python,Docker,我有一个名为python-example 容器id=c08e4ee85879 里面有一个python脚本,可以打印helloworld file.py 如果我运行我的映像: docker run python example输出的HELLO WORLD将打印在我的终端上,然后容器将退出 当我试图进入容器通过vim对脚本进行更改时,退出容器并将更改提交到新图像,然后尝试运行新图像,但没有打印任何内容。请参阅下面的步骤 docker run -it python-example bash vim f
python-example
容器id=c08e4ee85879
里面有一个python脚本,可以打印helloworld
file.py
如果我运行我的映像:
docker run python example
输出的HELLO WORLD
将打印在我的终端上,然后容器将退出
当我试图进入容器通过vim对脚本进行更改时,退出容器并将更改提交到新图像,然后尝试运行新图像,但没有打印任何内容。请参阅下面的步骤
docker run -it python-example bash
vim file.py
#make some changes by adding a new print statement "HELLO WORLD 2"
exit
docker commit c08e4ee85879 python-example2
docker run python-example2 #now nothing gets printed to terminal screen
当我输入新图像,然后运行python file.py时,输出会被打印出来
docker run -it python-example2 bash
python file.py
"HELLO WORLD"
"HELLO WORLD 2"
为什么会这样?在bash中提交更改时,映像是否无法运行?解决方案 将您的承诺更改为:
docker commit --change='CMD ["python", "file.py"]' c08e4ee85879 python-example2
解释
运行时:
docker运行-it python示例bash
您正在将默认命令(即python file.py
更改为bash
)
您可以使用docker ps
进行检查
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c08e4ee85879 python-example "bash" 32 seconds ago Up 30 seconds thirsty_hugle
使用
--change='CMD[“python”,“file.py”]
可以返回所需的命令。是否可以添加docker inspect python-example2的输出?
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c08e4ee85879 python-example "bash" 32 seconds ago Up 30 seconds thirsty_hugle