python-3.x - 在 docker python 中找不到应用程序

标签 python-3.x docker

当我在 Windows 10 docker 客户端上运行“docker-compose up”时,出现以下错误:

counterapp_web_1 |   File "manage.py", line 7, in <module>
counterapp_web_1 |     from app import app
counterapp_db_1 | 2018-01-26T05:09:23.517693Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
counterapp_web_1 | ImportError: No module named 'app', 

这是我的 dockerfile:

FROM python:3.4.5-slim

## make a local directory
RUN mkdir /counter_app
ENV PATH=$PATH:/counter_app
ENV PYTHONPATH /counter_app

# set "counter_app" as the working directory from which CMD, RUN, ADD references
WORKDIR /counter_app

# now copy all the files in this directory to /counter_app
ADD . .

# pip install the local requirements.txt
RUN pip install -r requirements.txt

# Listen to port 5000 at runtime
EXPOSE 5000

# Define our command to be run when launching the container
CMD ["python", "manage.py", "runserver"]

有一个manage.py调用文件夹app,在app下有__init__.py .

最佳答案

仔细检查 docker run 上的此错误是否为 because of your directory name :

__init__.py is imported using a directory. if you want to import it as app you should put __init__.py file in directory named app

a better option is just to rename __init__.py to app.py

所以文件夹名为 app,而不是 counter_app

关于python-3.x - 在 docker python 中找不到应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48456199/

相关文章:

Docker - 从容器修改主机的 IPTABLES

c# - Docker compose build/Docker build 连接拒绝在 macos 上进行 nuget

python - 从 csv 读取并检查 IP 地址可达性

python - 使用 pathlib 获取符号链接(symbolic link)的目标

java - 从java/jsp/html页面执行docker命令

nginx - Docker Nginx 禁用默认暴露端口 80

Docker 运行不显示任何输出

python-3.x - 有没有一种Python式的方法来计算总计达到整分钟的对

python - 如何在 Python 的同一类中将实例变量指定为关键字参数的默认值

python - 使用 PyQt4 和 python 3.5.2 运行 PyMoskito 示例时出错