简体   繁体   English

无法打开文件 'app.py': [Errno 2] 没有那个文件或目录

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

Dockerfile Dockerfile

FROM python:2.7
WORKDIR /app
COPY . /app
EXPOSE 80
CMD [ "python", "app.py" ]

app.py应用程序.py

def hello():
    return print("hello world")
hello()

I have run the following commands我运行了以下命令

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:在这种情况下, DockerfileCMD语句应该是:

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.

相关问题 Python 我无法在 flask 中打开文件“app.py” - Python I can't open file 'app.py' in flask 无法打开文件'file.py':[Errno 2] 没有这样的文件或目录 - Can't open file 'file.py': [Errno 2] No such file or directory 无法打开文件'menu.py':[Errno 2]没有这样的文件或目录 - Can't open file 'menu.py': [Errno 2] No such file or directory 无法打开文件'.manage.py':[Errno 2] 没有这样的文件或目录 - can't open file '.manage.py': [Errno 2] No such file or directory 无法打开文件“audioAnalysis.py”:[Errno 2] 没有这样的文件或目录 - Can't open file 'audioAnalysis.py': [Errno 2] No such file or directory 无法打开文件“import.py”:[Errno 2] 没有这样的文件或目录 - can't open file 'import.py' :[Errno 2] No such file or directory 无法打开文件 'main.py': [Errno 2] 没有那个文件或目录 - Can't open file 'main.py': [Errno 2] No such file or directory 无法打开文件 'manage.py': [Errno 2] 没有那个文件或目录 - Can't open file 'manage.py': [Errno 2] No such file or directory Dockerfile-python:无法打开文件'/usr/app/client.py':[Errno 2]没有这样的文件或目录 - Dockerfile - python: can't open file '/usr/app/client.py': [Errno 2] No such file or directory python3: 无法打开文件 '/app/manage.py': [Errno 2] 没有那个文件或目录 - python3: can't open file '/app/manage.py': [Errno 2] No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM