简体   繁体   English

如何使用docker依赖项运行python程序(或其他cmd)?

[英]How to run python program (or other cmd) with docker dependencies?

I have some python package utils in container ./utils , and some other dependencies, but I have a python program start.py which I want to run in host machine. 我在容器./utils有一些python软件包utils ,还有其他一些依赖项,但是我有一个要在主机中运行的python程序start.py

Is there any way to do it? 有什么办法吗? We can consider the scenario is that the start.py is in host machine which could be easier to use by user and the dependencies are in docker(no need for user to build) 我们可以考虑以下情况: start.py在主机中,可能更易于用户使用,而依赖项在docker中(无需用户构建)

You can mount the start.py onto an ephemeral container and then run the python script inside the container. 您可以将start.py挂载到临时容器上,然后在容器内运行python脚本。 If the script produces an output that needs to be stored on the host, you can mount the output's location too. 如果脚本产生的输出需要存储在主机上,则也可以安装输出的位置。

docker run --rm --entrypoint 'python /tmp/start.py' -v <location of script on host>:/tmp/start.py -v <location where you want to store output on host>:<location where output is stored inside the container> <image_name>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM