当我运行我的app.py文件时,我可以在本地主机上访问它,并且它可以工作。
运行后(没有问题):docker build -t flask-container .
运行docker run -p 5000:5000 flask-container
我得到:from helpers import apology, login_required, usd
ModuleNotFoundError: No module named 'helpers'
在app.py我有:from helpers import apology, login_required, usd
我试过在主文件夹中放入一个空的__init__.py
文件夹,仍然不起作用。
问题:我如何修复模块未发现错误时,试图运行docker?
Dockerfile
FROM python:3.8-alpine
# By default, listen on port 5000
EXPOSE 5000/tcp
# Set the working directory in the container
WORKDIR /app
# Copy the dependencies file to the working directory
COPY requirements.txt .
# Install any dependencies
RUN pip install -r requirements.txt
# Copy the content of the local src directory to the working directory
COPY app.py .
# Specify the command to run on container start
CMD [ "python", "./app.py" ]
让
flask===2.1.0
flask_session
Python版本:3.10.5请将helpers.py文件也复制到工作目录。
COPY helpers.py .
或
ADD . /app
#This will add all files in the current local dir to /app