[英]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.