[英]can't open file 'app.py': [Errno 2] No such file or directory
Trying to get started with python & Docker, managed to get Docker working with a PHP example but struggling to get it working with a python file.尝试开始使用 python 和 Docker,设法让 Docker 使用 PHP 示例,但努力让它使用 python 文件。
I am trying to get a simple hello world docker container running to simply print "Hello world"我正在尝试让一个简单的 hello world docker 容器运行以简单地打印“Hello world”
FROM python:2.7
WORKDIR /app
COPY . /app
EXPOSE 80
CMD [ "python", "app.py" ]
def hello():
return print("hello world")
hello()
docker build -t test .
docker run -p 80:80 test
Expected result: containerised app running on port 80预期结果:容器化应用运行在 80 端口
Actual result:python: can't open file './app.py': [Errno 2] No such file or directory实际结果:python: can't open file './app.py': [Errno 2] No such file or directory
According to your comment, the directory structure seems to be根据您的评论,目录结构似乎是
Dockerfile
src/
app.py
In this case, the CMD
statement in your Dockerfile
should be:在这种情况下, Dockerfile
的CMD
语句应该是:
CMD [ "python", "src/app.py" ]
This is because of your app.py
residing inside src
folder with respect to the mentioned WORKDIR
.这是因为您的app.py
位于src
文件夹中,与提到的WORKDIR
。
WORKDIR
makes any subsequent commands run within that work dir you specified. WORKDIR
使任何后续命令在您指定的工作目录中运行。 So, the next line COPY. /app
所以,下一行COPY. /app
COPY. /app
will copy files to this directory ./app/app
not ./app
COPY. /app
会将文件复制到此目录./app/app
而不是./app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.