[英]No such file or directory error when running Docker container
I have a REST Api for a Flask app with an Oracle database for which I use Oracle Instant Client.我有一个用于 Flask 应用程序的 REST Api,其中包含我使用 Oracle Instant Client 的 Oracle 数据库。
I managed to run the app from my computer and it works fine and my task is to make a Docker file for this app.我设法从我的计算机上运行该应用程序,它运行良好,我的任务是为此应用程序制作一个 Docker 文件。 I don`t have much experience with Docker.
我对 Docker 没有太多经验。
This is the Dockerfile that I have written这是我写的Dockerfile
FROM python:3.7.5-slim-buster
# Installing Oracle instant client
WORKDIR /opt/oracle
RUN apt-get update && apt-get install -y libaio1 wget unzip \
&& wget
https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-
linuxx64.zip \
&& unzip instantclient-basiclite-linuxx64.zip \
&& rm -f instantclient-basiclite-linuxx64.zip \
&& cd /opt/oracle/instantclient* \
&& rm -f *jdbc* *occi* *mysql* *README *jar uidrvci genezi adrci \
&& echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-
instantclient.conf \
&& ldconfig
WORKDIR /app
COPY . .
EXPOSE 5000
CMD ["python", "/app/__init__.py"]
I use the following commands:我使用以下命令:
python: can't open file '/app/__init__.py': [Errno 2] No such file or directory
python: can't open file '/app/__init__.py': [Errno 2] No such file or directory
The folder structure of the app on my computer is the following: C:\\Proiecte_python\\Flask_Docker_App-Start\\app and in app are the instant oracle client the python file and the Dockerfile.我电脑上app的文件夹结构如下:C:\\Proiecte_python\\Flask_Docker_App-Start\\app,app里面是即时oracle客户端python文件和Dockerfile。
Can please someone help me because I think it`s something wrong in the Dockerfile CMD path or something like that.请有人帮助我,因为我认为 Dockerfile CMD 路径或类似的东西有问题。 I have tried many variants but none work
我尝试了很多变体,但没有一个工作
The last line of your Dockerfile Dockerfile 的最后一行
CMD ["python", "/app/__init__.py"]
is equivalent to executing相当于执行
python /app/__init__.py
The error you are getting is that the file __init__.py does not exist.您得到的错误是文件__init__.py不存在。
The lines线条
WORKDIR /app
COPY . .
Are telling your container to CD into the /app directory then copy all files from your host machine (Eg your physical machine) into the /app directory of the container .告诉您的容器将 CD 放入/app目录,然后将所有文件从您的主机(例如您的物理机)复制到容器的/app目录中。 (the COPY . . means to copy from the current directory of your host - eg the location you're running docker commands from - into the current directory of the container - /app ).
( COPY . .表示从主机的当前目录(例如,您从中运行 docker 命令的位置)复制到容器的当前目录 - /app )。
It seems that as part of receiving the Dockerfile you should have also downloaded the __init.py__ file and then the Dockerfile would have copied that into your container for you.似乎作为接收 Dockerfile 的一部分,您还应该下载__init.py__文件,然后 Dockerfile 会将其复制到您的容器中。
Alternatively you may have missed steps in your instructions where you were meant to write your own __init.py__ file for testing.或者,您可能错过了说明中打算编写自己的__init.py__文件进行测试的步骤。
Either way your solutions are to find the __init.py__ file and put it into your current working directory ( C:\\Proiecte_python\\Flask_Docker_App-Start\\app ) and ensure that you run your docker build and docker run commands from that same directory eg -无论哪种方式,您的解决方案都是找到__init.py__文件并将其放入您当前的工作目录( C:\\Proiecte_python\\Flask_Docker_App-Start\\app )并确保您从同一目录运行docker build和docker run命令,例如 -
cd C:\Proiecte_python\Flask_Docker_App-Start\app
docker build <....>
docker run <....>
docker start <....>
Or your other solution is to go back to the instructions and ensure that you have created the python file and put it in the correct place.或者您的其他解决方案是返回说明并确保您已创建python文件并将其放在正确的位置。
As a very basic Flask/Docker tutorial see the below link作为一个非常基本的 Flask/Docker 教程,请参阅以下链接
https://runnable.com/docker/python/dockerize-your-flask-application https://runnable.com/docker/python/dockerize-your-flask-application
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.