【发布时间】:2017-11-08 03:48:55
【问题描述】:
我在 Ubuntu 17.04 Zesty 上使用 docker 17.05.0-cs edge。我有一个我构建的 gunicorn/Django 应用程序here。它在被 dockerized 之前运行良好,但是 gunicorn 在docker build 之后看不到静态文件。这里是Dockerfile:
# Dockerfile
# FROM base image to build upon
FROM phusion/baseimage
# RUN install python and pip
RUN apt-get update
RUN apt-get install -y python python-pip python-dev
# ENV set environment directory tree
ENV PROJECT=mysite
ENV CONTAINER_HOME=/opt
ENV CONTAINER_PROJECT=$CONTAINER_HOME/$PROJECT
# move to project WORKDIR
WORKDIR $CONTAINER_PROJECT
# COPY project to container directory
COPY . $CONTAINER_PROJECT
# RUN pip and install requirements
RUN pip install -r requirements.txt
# COPY start.sh into known container location
COPY start.sh /start.sh
# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000
# CMD execute start.sh to start the server running.
CMD ["/start.sh"]
# done!
应用程序运行并显示页面,有趣的是,它甚至应用了css 模板,同时说找不到bootstrap.css 或bootstrap.js。它不会执行脚本来切换菜单。当前的模板只是我最初构建的一个工件,新的甚至不会使用bootstrap.js 我很确定。它运行但切换不起作用,我知道这是bootstrap.js 的一个功能。这是sudo docker run -it -p 8000:8000 dockerized_site的输出:
Starting Gunicorn.
[2017-06-07 00:38:56 +0000] [1] [INFO] Starting gunicorn 19.6.0
[2017-06-07 00:38:56 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
[2017-06-07 00:38:56 +0000] [1] [INFO] Using worker: sync
[2017-06-07 00:38:56 +0000] [9] [INFO] Booting worker with pid: 9
[2017-06-07 00:38:56 +0000] [10] [INFO] Booting worker with pid: 10
[2017-06-07 00:38:56 +0000] [11] [INFO] Booting worker with pid: 11
Not Found: /js/bootstrap.min.js
Not Found: /js/jquery.js
Not Found: /js/bootstrap.min.js
Not Found: /favicon.ico
我将静态文件 url 模式附加到 urls.py,我很确定这与容器构建有关,或者可能与 settings.py 有关。也许我需要为静态文件添加一个环境目录?当然,我们非常感谢任何帮助。
【问题讨论】:
-
能否请您发布 gunicorn 引发的错误?
标签: python django docker dockerfile gunicorn