在Docker中执行python脚本

我从Docker开始。 我已经开始使用Python 3中的Hello World脚本。这是我的Dockerfile:

FROM ubuntu:latest RUN apt-get update RUN apt-get install python3 COPY . hello.py CMD python3 hello.py 

在同一个目录中,我有这个python脚本:

 if __name__ == "__main__": print("Hello World!"); 

我用这个命令build立了图像:

 docker build -t home/ubuntu-python-hello . 

到现在为止还挺好。 但是当我尝试用这个命令运行脚本时:

 docker run home/ubuntu-python-hello 

我得到这个错误:

 /usr/bin/python3: can't find '__main__' module in 'hello.py' 

我究竟做错了什么? 任何意见或build议被接受,我只是一个新手。

谢谢。

感谢Gerrat,我解决了这个问题:

 COPY hello.py hello.py 

代替

 COPY . hello.py 

你需要这样安装python并用-y确认。

运行apt-get update && apt-get install python3-dev -y