Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
docker python:在容器中提交更改,但新映像不运行_Python_Docker - Fatal编程技术网

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