泊坞窗python:在一个容器中提交的更改,但新的图像不运行
我有一个名为python-example
与container_id = c08e4ee85879
的Python图像
里面存在一个打印hello world
的python脚本
file.py
print "HELLO WORLD"
如果我运行我的图像: docker run python-example
输出HELLO WORLD
将被打印在我的terminal,然后容器将退出。
当我尝试通过viminput容器来对脚本进行更改时,请退出容器并将更改提交到新图像,然后尝试运行新图像,但不会打印任何内容。 请参阅以下步骤
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
当我input新的图像,然后运行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 run -it python-example 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
检查dockerfile参考 – CMD的更多信息
使用--change='CMD ["python", "file.py"]'
你可以得到想要的命令。