Skip to content

Commit

Permalink
Upgraded django-composed image
Browse files Browse the repository at this point in the history
  • Loading branch information
bunop committed May 31, 2019
1 parent fe8b6d1 commit 84c8d8e
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 86 deletions.
1 change: 1 addition & 0 deletions compose/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose-demo/
17 changes: 14 additions & 3 deletions compose/django/django-data/mysite_uwsgi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ socket = :8000
# the base directory (full path)
chdir = /var/uwsgi/mysite/

# Django's wsgi file
module = mysite.wsgi:application
# Django's wsgi file (https://stackoverflow.com/a/40496307)
mount = /mysite=mysite.wsgi:application
manage-script-name = true

# the PYTHON HOME environment (full path)
# home =
Expand Down Expand Up @@ -47,9 +48,19 @@ pidfile = /tmp/mysite.pid
# respawn processes taking more than 20 seconds
harakiri = 20

# enable verbose mode for harakiri
harakiri-verbose = true

# set internal http socket timeout
http-timeout = 120

# buffer sizes
buffer-size = 32768
post-buffering = 32768

# https://blog.gingerlime.com/2011/django-memory-leaks-part-i/comment-page-1/#comment-59726
# respawn processes after serving 5000 requests
max-requests = 5000
max-requests = 5000

# use the ip from X-Forwarded-For header instead of REMOTE_ADDR
log-x-forwarded-for = true
150 changes: 81 additions & 69 deletions compose/django/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,70 +1,82 @@

db:
# get the latest mysql server
image: mysql:5.6

# Set db environment
environment:
MYSQL_ROOT_PASSWORD: my-secret-pw

# to export volume, as recommeded in https://registry.hub.docker.com/u/library/mysql/
volumes:
- "./mysql-data:/var/lib/mysql"
- "/etc/localtime:/etc/localtime:ro"


# a variant of db image using postgresql Database
# db:
# # get the latest postgres server
# image: postgres:9.6
#
# # Set db environment
# environment:
# POSTGRES_PASSWORD: my-secret-pw
#
# # to export volume, as recommeded in https://registry.hub.docker.com/u/library/mysql/
# volumes:
# - "./postgres-data:/var/lib/postgresql/data"
# - "/etc/localtime:/etc/localtime:ro"


uwsgi:
# a custom image for django
build: ./uwsgi

# exec a different command from image
command: uwsgi --ini /var/uwsgi/mysite_uwsgi.ini

# set working dir for uwsgi
working_dir: /var/uwsgi/

# define volumes
volumes:
- "./django-data/:/var/uwsgi/"
- "/etc/localtime:/etc/localtime:ro"

# Expose the default port

# link container to database
links:
- db


nginx:
# a custom image for NGINX
build: ./nginx

volumes:
- "/etc/localtime:/etc/localtime:ro"
- "./nginx/conf.d/:/etc/nginx/conf.d/"

# get volumes from uwsgi
volumes_from:
- uwsgi

ports:
- "10080:80"

# link container uwsgi
links:
- uwsgi
version: "3.2"
services:
# Create a composed Django-Postgres-NGINX instance
db:
# get the latest mysql server
image: mariadb:10.1

# Set db environment
environment:
MYSQL_ROOT_PASSWORD: my-secret-pw

# to export volume, as recommeded in https://registry.hub.docker.com/u/library/mysql/
volumes:
- type: bind
source: ./mysql-data/
target: /var/lib/mysql


# # a variant of db image using postgresql Database
# pg:
# # get the latest postgres server
# image: postgres:9.6
#
# # Set db environment
# environment:
# POSTGRES_PASSWORD: my-secret-pw
#
# # to export volume, as recommeded in https://registry.hub.docker.com/u/library/mysql/
# volumes:
# - type: bind
# source: ./postgres-data/
# target: /var/lib/postgresql/data


uwsgi:
# a custom image for django
build: ./uwsgi

# exec a different command from image
command: uwsgi --ini /var/uwsgi/mysite_uwsgi.ini

# set working dir for uwsgi
working_dir: /var/uwsgi/

# define volumes
volumes:
- type: bind
source: ./django-data/
target: /var/uwsgi/

# Expose the default port

# link container to database
links:
- db
- pg


nginx:
# a custom image for NGINX
build: ./nginx

volumes:
- type: bind
source: ./nginx/conf.d/
target: /etc/nginx/conf.d/

- type: bind
source: ./django-data/
target: /var/uwsgi/

ports:
- "10080:80"

# link container uwsgi
links:
- uwsgi


networks:
default:
13 changes: 7 additions & 6 deletions compose/django/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@

#
# VERSION 0.2
# DOCKER-VERSION 1.9.1
# AUTHOR: Paolo Cozzi <paolo.cozzi@ptp.it>
# VERSION 0.3
# DOCKER-VERSION 17.05.0-ce
# AUTHOR: Paolo Cozzi <paolo.cozzi@ibba.cnr.it>
# DESCRIPTION: A nginx container to work with django
# TO_BUILD: docker build --rm -t django_nginx .
# TO_RUN: docker run -d -P django_nginx
# TO_TAG: docker tag django_nginx:latest django_nginx:0.2
# TO_TAG: docker tag django_nginx:latest django_nginx:0.3
#

# Get the last stable nginx image
FROM nginx:1.11
FROM nginx:1.16

MAINTAINER Paolo Cozzi <[email protected]>
# MAINTAINER is deprecated. Use LABEL instead
LABEL maintainer="[email protected]"

# Copy nginx configuration file in conf.d directory
COPY nginx.conf /etc/nginx/nginx.conf
Expand Down
15 changes: 8 additions & 7 deletions compose/django/uwsgi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@

#
# VERSION 0.5
# DOCKER-VERSION 1.9.1
# AUTHOR: Paolo Cozzi <paolo.cozzi@ptp.it>
# DESCRIPTION: A django container working on LTS django 1.11 on python 3
# VERSION 0.6
# DOCKER-VERSION 17.05.0-ce
# AUTHOR: Paolo Cozzi <paolo.cozzi@ibba.cnr.it>
# DESCRIPTION: A django container working on LTS django 2.2 on python 3
# TO_BUILD: docker build --rm -t django_uwsgi .
# TO_RUN: docker run -d -P django_uwsgi
# TO_TAG: docker tag django_uwsgi:latest django_uwsgi:0.5
# TO_TAG: docker tag django_uwsgi:latest django_uwsgi:0.6
#

# The official django image is deprecated in favor of the standard python image
FROM python:3.6
FROM python:3.7

MAINTAINER Paolo Cozzi <[email protected]>
# MAINTAINER is deprecated. Use LABEL instead
LABEL maintainer="[email protected]"

# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand Down
2 changes: 1 addition & 1 deletion compose/django/uwsgi/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
uwsgi
mysqlclient
psycopg2
Django==1.11
Django==2.2.1

0 comments on commit 84c8d8e

Please sign in to comment.