【发布时间】:2019-05-26 22:52:23
【问题描述】:
我的 docker 容器在我的 MacOS 机器上运行时似乎部署正确,但在我的远程 Ubuntu 18.04 服务器上运行时无法导入应用程序模块。它是一个使用 uwsgi 和 nginx 作为 Web 服务器的烧瓶应用程序。确切的错误是
ImportError: 没有名为“app”的模块
我尝试了以下各种文件的不同配置,但没有任何成功。
Dockerfile:
FROM python:3.5
RUN apt-get update
RUN apt-get install -y --no-install-recommends \
libatlas-base-dev gfortran nginx supervisor
RUN pip3 install uwsgi
COPY requirements.txt /project/requirements.txt
RUN pip3 install -r /project/requirements.txt
RUN useradd --no-create-home nginx
RUN rm /etc/nginx/sites-enabled/default
RUN rm -r /root/.cache
COPY nginx.conf /etc/nginx/
COPY flask-site-nginx.conf /etc/nginx/conf.d/
COPY uwsgi.ini /etc/uwsgi/
COPY supervisord.conf /etc/
COPY /app /project
WORKDIR /project
CMD ["/usr/bin/supervisord"]
主管:
[supervisord]
nodaemon=true
[program:uwsgi]
command=/usr/local/bin/uwsgi --ini /etc/uwsgi/uwsgi.ini --die-on-term
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:nginx]
command=/usr/sbin/nginx
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
uwsgi:
[uwsgi]
module = app.wsgi
callable = app
uid = nginx
gid = nginx
socket = /tmp/uwsgi.sock
chown-socket = nginx:nginx
chmod-socket = 664
cheaper = 1
processes = %(%k + 1)
非常感谢任何意见或建议 - 在此先感谢!
【问题讨论】:
-
您是否尝试过使用
docker run -ti --entrypoint /bin/bash运行容器并使用cd和ls手动查看?COPY /app /project看起来也很可疑。如果您的 Docker 构建上下文中没有可用的/app,那么COPY可能会失败。 -
上面的评论似乎值得一看。请告诉我们您的发现。
-
感谢您回复我!我能够解决这个问题 - 我需要它在该容器内创建一个名为 app 的新文件夹,然后将文件复制到该文件夹中。
标签: python docker flask docker-compose uwsgi