2017-06-07 62 views
1

我在Ubuntu 17.04 Zesty上使用docker 17.05.0-cs edge。我有一个我建立的gunicorn/Django应用程序here。在docker化之前它运行良好,但gunistorn在docker build之后无法看到静态文件。这里是Dockerfiledockerization后,Gunicorn找不到staticfiles

# 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! 

的应用程序运行并显示页面,滑稽,甚至一边说无法找到bootstrap.cssbootstrap.js应用css模板。它不会执行脚本来切换菜单。目前的模板只是我最初构建的工件,新的模板甚至不会使用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做。也许我需要为静态文件添加一个环境目录?当然,任何帮助都是值得赞赏的。

+1

请问您可以发布gunicorn引发的错误吗? – Robert

回答

1

这是你的问题:

css的都行工作:

<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet"> 

js的不工作(404):

<script src="{% static '/js/jquery.js' %}"></script> 

看到区别?

中/ JS

的通往/这解决您的问题:

<script src="{% static 'js/jquery.js' %}"></script> 

我克隆你的回购和固定的模板,我已经得到了解决您的问题。请修复另一个<script> s

+1

再次感谢!我已经纠正它并推到了主人身边。 – ThisGuyCantEven

+0

随时欢迎;) – Robert

1

请参阅https://docs.djangoproject.com/en/1.11/howto/static-files/deployment/ 用于静态文件部署。

但是,您可能想使用Nginx或Apache等Web服务器来为您的静态文件提供服务。您不应该使用Gunicorn来提供静态文件,特别是在制作过程中。 Gunicorn是为动态内容制作的WSGI服务器。

+0

在这种情况下,部署静态文件直到dockerizing应用程序。我最终会使用Nginx,我现在只是在测试。 – ThisGuyCantEven