简体   繁体   English

如何运行 docker 容器外的 python 文件

[英]How to run a python file which is present outside the docker container

Inside VM I created a docker container, Now there are some python files present outside the container(present in host directory of VM) how can I execute these python files from container anyone help me with this在 VM 内部我创建了一个 docker 容器,现在容器外部存在一些 python 文件(存在于 VM 的主机目录中)我如何从容器中执行这些 python 文件任何人都可以帮助我解决这个问题

You should mount the vm directory like this:你应该像这样挂载 vm 目录:

docker run -d -it --name your-container-name -v /host/path:/usr/local/bin container:image

Also you must be sure /host/path permissions are propperly set.您还必须确保正确设置了 /host/path 权限。 Volumes in docker docker 中的卷

you can copy or mount the python file inside the docker container then execute the python with CMD.您可以将 python 文件复制或挂载到 docker 容器中,然后使用 CMD 执行 python。

For ex: docker run -it -v myfile.py:/tmp/myfile.py python python /tmp/myfile.py例如: docker run -it -v myfile.py:/tmp/myfile.py python python /tmp/myfile.py

docker run -t -i -v <host_dir>:<container_dir> ubuntu /bin/bash By this command I'm able to access host directory by inside the container where the directories are mounted and can able to run python file present in host by container docker run -t -i -v <host_dir>:<container_dir> ubuntu /bin/bash 通过这个命令,我可以通过安装目录的容器内部访问主机目录,并且可以运行主机中存在的 python 文件按集装箱

暂无
暂无

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

相关问题 在 Docker 容器外运行 python 文件,该文件在 Docker 容器外导入 python 文件 - Run python file outside Docker container that imports a python file outside Docker container 如何从 docker 容器访问外部文件? - How to access a file outside from a docker container? 当容器在 Python 中运行时,在 Docker 容器之外创建一个文件 - Create a file outside of Docker container while container is running in Python 如何创建运行 python 脚本的 Docker 容器,该脚本将文件写入容器外部的位置 - How to create a Docker container that runs a python script that writes file to a location outside the container 在run -it / bin / bash之外的docker容器中发出运行python脚本的问题 - Issue running python scripts in docker container outside of run -it /bin/bash 如何挂载 docker 容器以便我可以运行存储在容器内部的 python 脚本 - How to mount a docker container so that I can run python scripts, which are stored in the inside of the container 如何将 docker 容器的 STDOUT 捕获到该容器外部的文件中? - How can I capture STDOUT of a docker container to a file OUTSIDE of that container? 如何在容器外部运行 docker 命令,并在主机上使用 cron? - How can i run docker commands outside container, with cron on the host? 如何在Docker的容器上运行Python服务器 - How to run Python server on Docker's container 如何在 expressjs Docker 容器中运行 Python - How to run Python inside an expressjs Docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM