andrecp / django-tutorial-docker-nginx-postgres Goto Github PK
View Code? Open in Web Editor NEWDjango tutorial running with Nginx, Gunicorn, PostgreSQL and docker-compose
License: Do What The F*ck You Want To Public License
Django tutorial running with Nginx, Gunicorn, PostgreSQL and docker-compose
License: Do What The F*ck You Want To Public License
Hi, n00b here. I just followed the tutorial but failed to run the project. Please can you help?
$ sh rebuild_docker.sh
postgres uses an image, skipping
Building django...
Step 0 : FROM python:2.7-onbuild
# Executing 3 build triggers
Trigger 0, COPY requirements.txt /usr/src/app/
Step 0 : COPY requirements.txt /usr/src/app/
---> Using cache
Trigger 1, RUN pip install --no-cache-dir -r requirements.txt
Step 0 : RUN pip install --no-cache-dir -r requirements.txt
---> Using cache
Trigger 2, COPY . /usr/src/app
Step 0 : COPY . /usr/src/app
---> Using cache
---> 69e2dca77370
Step 1 : ENV DJANGO_CONFIGURATION Docker
---> Using cache
---> 270fbc19c045
Step 2 : CMD gunicorn -c gunicorn_conf.py --chdir mysite mysite.wsgi:application --reload
---> Using cache
---> 625f575074fe
Successfully built 625f575074fe
Building nginx...
Step 0 : FROM nginx
---> 6886fb5a9b8d
Step 1 : MAINTAINER Andre Prado
---> Using cache
---> 4fe6f1f20017
Step 2 : COPY nginx.conf /etc/nginx/nginx.conf
---> Using cache
---> 2173090fed54
Successfully built 2173090fed54
Recreating djangotutorialdockernginxpostgres_postgres_1...
Recreating djangotutorialdockernginxpostgres_django_1...
Recreating djangotutorialdockernginxpostgres_nginx_1...
Name Command State Ports
-------------------------------------------------------------------------
djangotutorialdo gunicorn -c Exit 1
ckernginxpostgre gunicorn_conf.
s_django_1 ...
djangotutorialdo nginx -g daemon Up 443/tcp, 0.0.0.0
ckernginxpostgre off; :80->80/tcp
s_nginx_1
djangotutorialdo /docker- Up 5432/tcp
ckernginxpostgre entrypoint.sh
s_postgres_1 postgres
$ docker-compose run django /bin/sh -c 'cd mysite;python manage.py migrate'
/bin/sh: 1: cd: can't cd to mysite
python: can't open file 'manage.py': [Errno 2] No such file or directory
Hello,
Nice repo. Thanks for sharing. I want to learn docker in the context of django too. So I was curious. Did you follow the basic django tutorial or a more specific "django + docker" tutorial? It would be nice if you could add the link in the README.
Thanks,
Loic
Hey,
So I modified this project to work with my own Django app. I got it to work, except for the static files. All the requests end in a 403 error. Your project worked out of the box (including the static files) so it's probably my configuration that messed it up.
This is my folder structure:
djangostack
│ docker-compose.yml
│ Dockerfile
│ gunicorn_conf.py
│ README.md
│ rebuild_docker.sh
│ requirements.txt
│
└───nginx
│ │ Dockerfile
│ │ nginx.conf
│ │
└───vms
│ manage.py
│
├───static (This is where the staticfiles are collected)
│ └───admin
│ └───website
│
└───vms
│ │ init.py
│ │ settings.py
│ │ urls.py
│ │ wsgi.py
│
└───website
│ └───static
│ │ └───website
│ │ │ └───css
│ │ │ └───img
│ │ │ └───js
│ │
│ └───templates
│ │ └───website
│ │
│ │ admin.py
│ │ forms.py
│ │ init.py
│ │ models.py
│ │ tests.py
│ │ views.py
This is my nginx.conf:
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name example.org;
access_log /dev/stdout;
error_log /dev/stdout info;
location /static {
alias /usr/src/app/vms/static;
}
location / {
proxy_pass http://django:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
This is the static files section in my settings.py:
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.