简体   繁体   English

从Docker运行Python

[英]Run Python from Docker

I'm trying out Docker these days and I want to run create virtual environments in Python in Docker. 这些天,我正在尝试Docker,并且想在Docker中使用Python运行创建虚拟环境。 I downloaded Miniconda3 from docker hub and tested out with basic hello world program written in python. 我从docker hub下载了Miniconda3,并用python编写的基本hello world程序进行了测试。

I ran: 我跑了:

docker run -i-t continuumio/miniconda3 /bin/bash

Then on another terminal I ran: 然后在另一个终端上运行:

docker exec laughing_wing "python ~/Documents/Test/hello_world.py"

Where the name of docker container is laughing_wing, and my hello_world.py is in Documents/Test directory. docker容器的名称是aughing_wing,而我的hello_world.py在Documents / Test目录中。

But running the second command I get: 但是运行第二个命令,我得到:

"OCI runtime exec failed: exec failed: container_linux.go:344: starting container process caused "exec: \\"python ~/Documents/Test/hello_world.py\\": stat python ~/Documents/Test/hello_world.py: no such file or directory": unknown" “ OCI运行时exec失败:exec失败:container_linux.go:344:启动容器进程引起了“ exec:\\” python〜/ Documents / Test / hello_world.py \\“:统计信息python〜/ Documents / Test / hello_world.py:否此类文件或目录“:未知”

I'm confused about this. 我对此感到困惑。

Looks like you're trying to have the docker container run a python file from your machine. 看起来您正在尝试让docker容器从您的机器运行python文件。 The docker container is isolated from it's host, so you need to either create your own Docker image where you add the file, or mount the ~/Documents/Test directory to your docker container. Docker容器与其主机是隔离的,因此您需要在添加文件的位置创建自己的Docker映像,或者将〜/ Documents / Test目录安装到Docker容器。 Something like this: 像这样:

docker run -it -v ~/Documents/Test:/Test continuumio/miniconda3 /bin/bash

docker exec *container_name* "python /Test/hello_world.py"

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

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