简体   繁体   English

运行Docker容器时没有此类文件或目录错误

[英]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:我使用以下命令:

  1. docker build - < Dockerfile And the Docker image build with no errors docker build - < Dockerfile 并且 Docker 镜像构建没有错误
  2. docker run -d -p 5000:5000 (docker image id) docker run -d -p 5000:5000(docker 镜像 ID)
  3. docker start -ai (docker container id) And I get this error: python: can't open file '/app/__init__.py': [Errno 2] No such file or directory docker start -ai (docker container id) 我得到这个错误: 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 builddocker 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.

相关问题 在Docker容器中运行命令时出现奇怪的“无此类文件或目录”错误 - Bizarre “No such file or directory” error when running a command within a docker container 在docker上运行时,Python烧瓶重新加载器“Errno 2没有这样的文件或目录”错误 - Python flask reloader “Errno 2 No such file or directory” error when running on docker 在docker容器上运行flask应用程序:错误:python:无法打开文件&#39;//run.py&#39;:[Errno 2]没有这样的文件或目录Docker错误 - having on running flask app on docker container : Error: python: can't open file '//run.py': [Errno 2] No such file or directory Docker Error Docker 运行 Python 错误 - [错误 2] 没有这样的文件或目录 - Docker Running Python Error - [Error 2] No such file or directory 没有这样的文件或目录,在 .net core 中运行控制台应用程序时无法在 docker 容器中找到 Python.exe - No such file or directory, Unable to find Python.exe in docker container when running console app in .net core 在 docker 容器中运行 tensorflow 时出错 - Error running tensorflow in docker container 在 docker 容器中运行迁移时出错 - Error running migrations in a docker container 在Docker容器中运行python脚本时导入错误? - Import error when running python script inside docker container? 使用 venv 运行 docker 容器时找不到 gunicorn - gunicorn not found when running a docker container with venv 在 docker 容器上运行时,Flask 应用程序无法正常工作 - Flask App not working when running on docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM