2017-06-07 33 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

相關問題