如何将Python文件导入另一个Python文件中,以便在Docker中起作用?
当我运行我的app.py文件时,我可以在localhost上访问它,并且可以访问它。
运行后(没有问题): docker build -t flask -container。
当我运行时: docker run -p 5000:5000 flask -container
我得到:来自助手导入道歉,login_required,USD
modulenotfounderror:
app.py中的没有名为'helpers'的 模块。帮助者导入道歉,login_required,USD
我尝试在主文件夹中放入一个空的 __ INT __。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
.txt Python版本:3.10.5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请将helpers.py也复制到工作目录中。
或者
Please copy the helpers.py as well into the working directory.
OR