A project to get you started with Docker and Django.

Overview

Docker Django

tl;dr

$ git clone [email protected]:erroneousboat/docker-django.git
$ docker-compose up

Now you can access the application at https://localhost and the admin site at https://localhost/admin.

A project to get you started with Docker and Django. This is made to serve as an example for you to hack on, so I don't claim that this is the correct way to setup a system with Django and Docker. Thus, I advice to also look at other projects.

Stack and version numbers used:

Name Version
Django 2.1.4
Nginx 1.15
Postgresql 11.1
uWSGI 2.0.17.1

Folder structure

$ tree -L 1 --dirsfirst
.
├── config              # files needed for configuration
├── webapp              # actual webapp
├── docker-compose.yml  # docker-compose setup with container orchestration instructions
├── LICENSE             # license for this project
└── README.md           # this file

Setting up

Docker

See installation instructions at: docker documentation

Docker Compose

Install docker compose, see installation instructions at https://docs.docker.com/compose/install/

Django

Create django project in the webapp folder or copy a project to the webapp folder or use the sample project enclosed in this project and go directly to the section 'Fire it up':

# Be sure you have Django installed on your system
$ django-admin startproject <name_project>

Edit config/environment/development.env file and add the name of your project at DJANGO_PROJECT_NAME or just leave it as is to start the default application.

Edit the settings.py file with the correct database credentials and static root:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.environ.get('POSTGRES_NAME'),
        'USER': os.environ.get('POSTGRES_USER'),
        'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),
        'HOST': os.environ.get('POSTGRES_HOST'),
        'PORT': os.environ.get('POSTGRES_PORT'),
    }
}

STATIC_ROOT = '/srv/static-files'

Environment variables

The file config/environment/development.env contains the environment variables needed in the containers. You can edit this as you see fit, and at the moment these are the defaults that this project uses. However when you intend to use this, keep in mind that you should keep this file out of version control as it can hold sensitive information regarding your project. The file itself will contain some commentary on how a variable will be used in the container.

Fire it up

Start the container by issuing one of the following commands:

$ docker-compose up             # run in foreground
$ docker-compose up -d          # run in background

Other commands

Build images:

$ docker-compose build
$ docker-compose build --no-cache       # build without cache

See processes:

$ docker-compose ps                 # docker-compose processes
$ docker ps -a                      # docker processes (sometimes needed)
$ docker stats [container name]     # see live docker container metrics

See logs:

# See logs of all services
$ docker-compose logs

# See logs of a specific service
$ docker-compose logs -f [service_name]

Run commands in container:

# Name of service is the name you gave it in the docker-compose.yml
$ docker-compose run [service_name] /bin/bash
$ docker-compose run [service_name] python /srv/starter/manage.py shell
$ docker-compose run [service_name] env

Remove all docker containers:

docker rm $(docker ps -a -q)

Remove all docker images:

docker rmi $(docker images -q)

Some commands for managing the webapp

To initiate a command in an existing running container use the docker exec command.

# Find container_name by using docker-compose ps

# restart uwsgi in a running container.
$ docker exec [container_name] touch /etc/uwsgi/reload-uwsgi.ini

# create migration file for an app
$ docker exec -it [container-name] \
    python /srv/[project-name]/manage.py makemigrations scheduler

# migrate
$ docker exec -it [container-name] \
    python3 /srv/[project-name]/manage.py migrate

# get sql contents of a migration
$ docker exec -it [container-name] \
    python3 /srv/[project-name]/manage.py sqlmigrate [appname] 0001

# get to interactive console
$ docker exec -it [container-name] \
    python3 /srv/[project-name]/manage.py shell

# testing
docker exec [container-name] \
    python3 /srv/[project-name]/manage.py test

Troubleshooting

Q: I get the following error message when using the docker command:

FATA[0000] Get http:///var/run/docker.sock/v1.16/containers/json: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS? 

A: Add yourself (user) to the docker group, remember to re-log after!

$ usermod -a -G docker <your_username>
$ service docker restart

Q: Changes in my code are not being updated despite using volumes.

A: Remember to restart uWSGI for the changes to take effect.

# Find container_name by using docker-compose ps
$ docker exec [container_name] touch /etc/uwsgi/reload-uwsgi.ini
Comments
  • Nginx server can't connect with webapp container

    Nginx server can't connect with webapp container

    I'm trying to use this setup with an existing django project. I've mounted my code as a volume in the webapp directory at <local_dir>:/srv/<project_name>.

    When I run docker-compose up -d I get the following error straight away in the logs:

    webserver_1  | 2017/09/26 15:13:35 [emerg] 8#8: host not found in upstream "webapp:8000" in /etc/nginx/nginx.conf:19
    webserver_1  | nginx: [emerg] host not found in upstream "webapp:8000" in /etc/nginx/nginx.conf:19
    

    And then both the webapp and webserver containers exit without reporting anything further in the logs.

    Any ideas how to improve the logging for the purposes of debugging, or what might be happening here?

    opened by rumski20 4
  • Problems firing the container up

    Problems firing the container up

    Hey,

    I'm trying to run the container, but this is what my terminal outputs after entering $ docker-compose up:

    Successfully built 35a9736e0654
    Creating dockerdjango_app_1
    Attaching to dockerdjango_datastore_1, dockerdjango_db_1, dockerdjango_app_1
    db_1        | The files belonging to this database system will be owned by user "postgres".
    db_1        | This user must also own the server process.
    db_1        | 
    db_1        | The database cluster will be initialized with locale "en_US.utf8".
    db_1        | The default database encoding has accordingly been set to "UTF8".
    db_1        | The default text search configuration will be set to "english".
    db_1        | 
    db_1        | Data page checksums are disabled.
    db_1        | 
    db_1        | fixing permissions on existing directory /var/lib/postgresql/data ... ok
    db_1        | creating subdirectories ... ok
    db_1        | selecting default max_connections ... 100
    db_1        | selecting default shared_buffers ... 128MB
    db_1        | selecting dynamic shared memory implementation ... posix
    db_1        | creating configuration files ... ok
    db_1        | creating template1 database in /var/lib/postgresql/data/base/1 ... ok
    db_1        | initializing pg_authid ... ok
    db_1        | initializing dependencies ... ok
    db_1        | creating system views ... ok
    db_1        | loading system objects' descriptions ... ok
    db_1        | creating collations ... ok
    db_1        | creating conversions ... ok
    db_1        | creating dictionaries ... ok
    db_1        | setting privileges on built-in objects ... ok
    db_1        | creating information schema ... ok
    db_1        | loading PL/pgSQL server-side language ... ok
    db_1        | vacuuming database template1 ... ok
    dockerdjango_datastore_1 exited with code 0
    db_1        | copying template1 to template0 ... ok
    db_1        | copying template1 to postgres ... ok
    db_1        | syncing data to disk ... ok
    db_1        | 
    db_1        | WARNING: enabling "trust" authentication for local connections
    db_1        | You can change this by editing pg_hba.conf or using the option -A, or
    db_1        | --auth-local and --auth-host, the next time you run initdb.
    db_1        | 
    db_1        | Success. You can now start the database server using:
    db_1        | 
    db_1        |     postgres -D /var/lib/postgresql/data
    db_1        | or
    db_1        |     pg_ctl -D /var/lib/postgresql/data -l logfile start
    db_1        | 
    db_1        | waiting for server to start....LOG:  database system was shut down at 2016-01-07 08:56:29 UTC
    db_1        | LOG:  MultiXact member wraparound protections are now enabled
    db_1        | LOG:  database system is ready to accept connections
    db_1        | LOG:  autovacuum launcher started
    db_1        |  done
    db_1        | server started
    db_1        | ALTER ROLE
    db_1        | 
    db_1        | 
    db_1        | /docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
    db_1        | 
    db_1        | LOG:  received fast shutdown request
    db_1        | LOG:  aborting any active transactions
    db_1        | LOG:  autovacuum launcher shutting down
    db_1        | LOG:  shutting down
    db_1        | waiting for server to shut down....LOG:  database system is shut down
    db_1        |  done
    db_1        | server stopped
    db_1        | 
    db_1        | PostgreSQL init process complete; ready for start up.
    db_1        | 
    db_1        | LOG:  database system was shut down at 2016-01-07 08:56:30 UTC
    db_1        | LOG:  MultiXact member wraparound protections are now enabled
    db_1        | LOG:  database system is ready to accept connections
    db_1        | LOG:  autovacuum launcher started
    app_1       | *** Running /etc/my_init.d/00_regen_ssh_host_keys.sh...
    app_1       | No SSH host key available. Generating one...
    app_1       | Creating SSH2 RSA key; this may take some time ...
    app_1       | Creating SSH2 DSA key; this may take some time ...
    app_1       | Creating SSH2 ECDSA key; this may take some time ...
    app_1       | Creating SSH2 ED25519 key; this may take some time ...
    app_1       | invoke-rc.d: policy-rc.d denied execution of restart.
    app_1       | *** Running /etc/my_init.d/setup.sh...
    app_1       | *** /etc/my_init.d/setup.sh failed with status 127
    app_1       | 
    app_1       | *** Killing all processes...
    dockerdjango_app_1 exited with code 1
    

    I have no idea why the datastore exited. I did check of /etc/my_init,d/setup.sh actually exists however, and the answer is no. The entire my_init.d folder is missing, actually. Any ideas on how to solve this?

    opened by ghost 4
  • Binary file 'template' in project

    Binary file 'template' in project

    https://github.com/erroneousboat/docker-django/blob/master/config/utils/template/template is apparently a binary? May I ask what it is and where it came from?

    Please close if this is not an issue. Thanks!

    enhancement 
    opened by fearofcode 3
  • http redirecting to https

    http redirecting to https

    e14ff89 http://localhost:9080/ redirects to https://localhost:9080/

    Ubuntu 16.04

    ~/study/docker/docker-django/services/webserver/config master
    ❯ docker version
    Client:
     Version:      1.11.1
     API version:  1.23
     Go version:   go1.5.4
     Git commit:   5604cbe
     Built:        Tue Apr 26 23:43:49 2016
     OS/Arch:      linux/amd64
    
    Server:
     Version:      1.11.1
     API version:  1.23
     Go version:   go1.5.4
     Git commit:   5604cbe
     Built:        Tue Apr 26 23:43:49 2016
     OS/Arch:      linux/amd64
    
    ~/study/docker/docker-django/services/webserver/config master
    ❯ docker-compose --version
    docker-compose version 1.7.1, build 6c29830
    
    opened by tony 3
  • Can't run starter-project

    Can't run starter-project

    Hi! Thanks for your project, it's pretty useful for me. I have used previous version, but got problem with current release. Literally, I can't run starter project. All containers are completely done, all looks fine, but I can't get any response on MYIP:80, or MYIP:443.

    logs:

    ➜  docker-django git:(master) ls
    LICENSE            README.md          circle.yml         config             docker-compose.yml services           webapp
    ➜  docker-django git:(master) docker-compose up
    Pulling db (postgres:9.4)...
    9.4: Pulling from library/postgres
    523ef1d23f22: Pull complete
    140f9bdfeb97: Pull complete
    8b57c6bf5c36: Pull complete
    ada8aa55613a: Pull complete
    b3de40c730c6: Pull complete
    7b8f7ba65711: Pull complete
    1bb8b8636476: Pull complete
    eca1007b842c: Pull complete
    189c3f75d39c: Pull complete
    b17cf3653712: Pull complete
    0b26aa7cec73: Pull complete
    31fca6a6d25c: Pull complete
    67eebf86eece: Pull complete
    6b4a2f54d551: Pull complete
    dc6bef69cb62: Pull complete
    392fdc82075f: Pull complete
    75a9a1efb957: Pull complete
    8249cabadf94: Pull complete
    553a94d3ee6d: Pull complete
    2e5da4125733: Pull complete
    8692541324b3: Pull complete
    Digest: sha256:f185069f51973c98b553e4b742fc9fd8bb8cec758c223ad8c64d6cb76dd9c863
    Status: Downloaded newer image for postgres:9.4
    Creating dockerdjango_db_1
    Building webapp
    Step 1 : FROM python:3.4
    3.4: Pulling from library/python
    5c63804eac90: Pull complete
    ce2b29af7753: Pull complete
    5c2bdca41b86: Pull complete
    b48f4076b06d: Pull complete
    d6788afe8670: Pull complete
    bbdcc687a0f0: Pull complete
    e947b4ddfa1b: Pull complete
    67716873f83e: Pull complete
    a061b101ffad: Pull complete
    11fe22a6a6d3: Pull complete
    453cd3efd83e: Pull complete
    Digest: sha256:0b53d27ef6eab3d340f8566601cb42fb8831f6a0368b622341c8f2eb30fdbd7b
    Status: Downloaded newer image for python:3.4
     ---> 453cd3efd83e
    Step 2 : ADD ./webapp/starter /srv/starter
     ---> bb2c4b8b0191
    Removing intermediate container 50a0f5ff7fde
    Step 3 : ADD ./webapp/config/requirements.txt /srv/starter/
     ---> 0acf93c2e437
    Removing intermediate container df40bd08280a
    Step 4 : RUN pip3 install -r /srv/starter/requirements.txt
     ---> Running in 6de42a4895e9
    Collecting django==1.9.1 (from -r /srv/starter/requirements.txt (line 1))
      Downloading Django-1.9.1-py2.py3-none-any.whl (6.6MB)
    Collecting uwsgi==2.0.11.1 (from -r /srv/starter/requirements.txt (line 2))
      Downloading uwsgi-2.0.11.1.tar.gz (782kB)
    Collecting psycopg2==2.6.1 (from -r /srv/starter/requirements.txt (line 3))
      Downloading psycopg2-2.6.1.tar.gz (371kB)
    Installing collected packages: django, uwsgi, psycopg2
      Running setup.py install for uwsgi
      Running setup.py install for psycopg2
    Successfully installed django-1.9.1 psycopg2-2.6.1 uwsgi-2.0.11.1
     ---> 8cb8dfda9fa4
    Removing intermediate container 6de42a4895e9
    Step 5 : ADD ./webapp/config/start.sh /
     ---> 34f9302090bc
    Removing intermediate container ac45ecb9b981
    Step 6 : ADD ./webapp/config/django-uwsgi.ini /etc/uwsgi/django-uwsgi.ini
     ---> 6f338cf307a1
    Removing intermediate container cc8956bbaa27
    Step 7 : ADD ./webapp/config/database-check.py /srv/config/database-check.py
     ---> 6a69b18bcde9
    Removing intermediate container e61053d06816
    Step 8 : RUN adduser --no-create-home --disabled-login --group --system django
     ---> Running in 8cddddcd366d
    Adding system user `django' (UID 104) ...
    Adding new group `django' (GID 108) ...
    Adding new user `django' (UID 104) with group `django' ...
    Not creating home directory `/home/django'.
     ---> d65bd967ca77
    Removing intermediate container 8cddddcd366d
    Step 9 : RUN chown -R django:django /srv/starter
     ---> Running in a2c69aa27461
     ---> a1488a5fca17
    Removing intermediate container a2c69aa27461
    Step 10 : CMD ./start.sh
     ---> Running in a3a2dc807025
     ---> 6e7461918ece
    Removing intermediate container a3a2dc807025
    Successfully built 6e7461918ece
    Creating dockerdjango_webapp_1
    Building webserver
    Step 1 : FROM nginx:1.9.6
    1.9.6: Pulling from library/nginx
    a719479f5894: Pull complete
    91bac885982d: Pull complete
    3df5aff384fc: Pull complete
    4f3dc531a45a: Pull complete
    687dd94c3fd3: Pull complete
    c82313fe3553: Pull complete
    2382c1a417f1: Pull complete
    ae6f47df6e10: Pull complete
    011ed111f209: Pull complete
    a155348e45f6: Pull complete
    341926a0a917: Pull complete
    81415e35fc6c: Pull complete
    Digest: sha256:55aa237fd10b203d2160b65c33b444c8dd94ebdbe121f3ff0e05daa496301c70
    Status: Downloaded newer image for nginx:1.9.6
     ---> 81415e35fc6c
    Step 2 : ADD ./services/webserver/config/start.sh /
     ---> 7375523f5c7e
    Removing intermediate container 063a6e4bd91d
    Step 3 : RUN chmod +x start.sh
     ---> Running in 55b57e098d8c
     ---> f7c739b05833
    Removing intermediate container 55b57e098d8c
    Step 4 : ADD ./config/utils/template/template /usr/local/bin/template
     ---> 3a0157d40ec4
    Removing intermediate container e9f32a3034df
    Step 5 : RUN chmod +x /usr/local/bin/template
     ---> Running in 811d8c9364e8
     ---> c0c186b4fb88
    Removing intermediate container 811d8c9364e8
    Step 6 : ADD ./services/webserver/config/nginx.tmpl /
     ---> 554b81cf6e7a
    Removing intermediate container af463ba0be19
    Step 7 : ADD ./services/webserver/config/*.crt /etc/ssl/certs/
     ---> 9502a719ed2d
    Removing intermediate container 837c3092495b
    Step 8 : ADD ./services/webserver/config/*.key /etc/ssl/private/
     ---> c68093d4978a
    Removing intermediate container f381802e4a3a
    Step 9 : CMD ./start.sh
     ---> Running in 77d8e7f21fb0
     ---> 30a92014e828
    Removing intermediate container 77d8e7f21fb0
    Successfully built 30a92014e828
    Creating dockerdjango_webserver_1
    Attaching to dockerdjango_db_1, dockerdjango_webapp_1, dockerdjango_webserver_1
    webapp_1    | ==> Django setup, executing: flush
    webapp_1    | ==> Django setup, executing: migrate
    db_1        | The files belonging to this database system will be owned by user "postgres".
    db_1        | This user must also own the server process.
    db_1        |
    webapp_1    | Operations to perform:
    webapp_1    |   Apply all migrations: sessions, auth, admin, contenttypes
    db_1        | The database cluster will be initialized with locale "en_US.utf8".
    webapp_1    | Running migrations:
    db_1        | The default database encoding has accordingly been set to "UTF8".
    db_1        | The default text search configuration will be set to "english".
    webapp_1    |   Rendering model states... DONE
    db_1        |
    webapp_1    |   Applying contenttypes.0001_initial... OK
    webapp_1    |   Applying auth.0001_initial... OK
    db_1        | Data page checksums are disabled.
    db_1        |
    db_1        | fixing permissions on existing directory pgdata ... ok
    webapp_1    |   Applying admin.0001_initial... OK
    db_1        | creating subdirectories ... ok
    webapp_1    |   Applying admin.0002_logentry_remove_auto_add... OK
    webapp_1    |   Applying contenttypes.0002_remove_content_type_name... OK
    db_1        | selecting default max_connections ... 100
    webapp_1    |   Applying auth.0002_alter_permission_name_max_length... OK
    db_1        | selecting default shared_buffers ... 128MB
    webapp_1    |   Applying auth.0003_alter_user_email_max_length... OK
    webapp_1    |   Applying auth.0004_alter_user_username_opts... OK
    db_1        | selecting dynamic shared memory implementation ... posix
    webapp_1    |   Applying auth.0005_alter_user_last_login_null... OK
    db_1        | creating configuration files ... ok
    webapp_1    |   Applying auth.0006_require_contenttypes_0002... OK
    db_1        | creating template1 database in pgdata/base/1 ... ok
    webapp_1    |   Applying auth.0007_alter_validators_add_error_messages... OK
    db_1        | initializing pg_authid ... ok
    webapp_1    |   Applying sessions.0001_initial... OK
    db_1        | initializing dependencies ... ok
    webapp_1    | ==> Django setup, executing: collectstatic
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/fonts/LICENSE.txt'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/fonts/Roboto-Light-webfont.woff'
    db_1        | creating system views ... ok
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/fonts/Roboto-Bold-webfont.woff'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/fonts/Roboto-Regular-webfont.woff'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/fonts/README.txt'
    db_1        | loading system objects' descriptions ... ok
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/prepopulate.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/collapse.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/calendar.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/urlify.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/actions.min.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/jquery.init.js'
    db_1        | creating collations ... ok
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/collapse.min.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/actions.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/core.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/inlines.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/SelectFilter2.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/timeparse.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/inlines.min.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/SelectBox.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/prepopulate.min.js'
    db_1        | creating conversions ... ok
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/vendor/xregexp/xregexp.min.js'
    db_1        | creating dictionaries ... ok
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/vendor/xregexp/LICENSE-XREGEXP.txt'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/vendor/jquery/jquery.min.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/vendor/jquery/LICENSE-JQUERY.txt'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/vendor/jquery/jquery.js'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/selector-icons.svg'
    db_1        | setting privileges on built-in objects ... ok
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/tooltag-add.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/calendar-icons.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/LICENSE'
    db_1        | creating information schema ... ok
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/icon-yes.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/tooltag-arrowright.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/icon-alert.svg'
    db_1        | loading PL/pgSQL server-side language ... ok
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/sorting-icons.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/icon-addlink.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/icon-no.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/icon-changelink.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/icon-unknown-alt.svg'
    db_1        | vacuuming database template1 ... ok
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/icon-calendar.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/inline-delete.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/icon-deletelink.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/icon-clock.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/search.svg'
    db_1        | copying template1 to template0 ... ok
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/README.txt'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/icon-unknown.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/gis/move_vertex_off.svg'
    db_1        | copying template1 to postgres ... ok
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/img/gis/move_vertex_on.svg'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/css/rtl.css'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/css/fonts.css'
    db_1        | syncing data to disk ... ok
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/css/forms.css'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/css/login.css'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/css/base.css'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/css/dashboard.css'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/css/widgets.css'
    webapp_1    | Copying '/usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/css/changelists.css'
    db_1        |
    webapp_1    |
    webapp_1    | 56 static files copied to '/srv/static-files'.
    db_1        | WARNING: enabling "trust" authentication for local connections
    db_1        | You can change this by editing pg_hba.conf or using the option -A, or
    webapp_1    | ==> Starting uWSGI ...
    db_1        | --auth-local and --auth-host, the next time you run initdb.
    webapp_1    | *** Starting uWSGI 2.0.11.1 (64bit) on [Mon Jan 25 03:41:12 2016] ***
    db_1        |
    db_1        | Success. You can now start the database server using:
    db_1        |
    db_1        |     postgres -D pgdata
    db_1        | or
    webapp_1    | compiled with version: 4.9.2 on 25 January 2016 03:40:06
    db_1        |     pg_ctl -D pgdata -l logfile start
    db_1        |
    webapp_1    | os: Linux-4.1.13-boot2docker #1 SMP Fri Nov 20 19:05:50 UTC 2015
    webapp_1    | nodename: 3e264d68836e
    db_1        | waiting for server to start....LOG:  database system was shut down at 2016-01-25 03:38:07 UTC
    webapp_1    | machine: x86_64
    db_1        | LOG:  MultiXact member wraparound protections are now enabled
    db_1        | LOG:  database system is ready to accept connections
    webapp_1    | clock source: unix
    db_1        | LOG:  autovacuum launcher started
    webapp_1    | pcre jit disabled
    webapp_1    | detected number of CPU cores: 1
    webapp_1    | current working directory: /
    db_1        |  done
    webapp_1    | detected binary path: /usr/local/bin/uwsgi
    webapp_1    | uWSGI running as root, you can use --uid/--gid/--chroot options
    db_1        | server started
    webapp_1    | *** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
    db_1        | ALTER ROLE
    webapp_1    | *** WARNING: you are running uWSGI without its master process manager ***
    webapp_1    | your processes number limit is 1048576
    webapp_1    | your memory page size is 4096 bytes
    webapp_1    | detected max file descriptor number: 1048576
    webapp_1    | *** starting uWSGI Emperor ***
    db_1        |
    webapp_1    | *** has_emperor mode detected (fd: 5) ***
    db_1        |
    webapp_1    | [uWSGI] getting INI configuration from /etc/uwsgi/django-uwsgi.ini
    db_1        | /docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
    webapp_1    | *** Starting uWSGI 2.0.11.1 (64bit) on [Mon Jan 25 03:41:12 2016] ***
    db_1        |
    webapp_1    | compiled with version: 4.9.2 on 25 January 2016 03:40:06
    webapp_1    | os: Linux-4.1.13-boot2docker #1 SMP Fri Nov 20 19:05:50 UTC 2015
    db_1        | LOG:  received fast shutdown request
    webapp_1    | nodename: 3e264d68836e
    db_1        | LOG:  aborting any active transactions
    webapp_1    | machine: x86_64
    db_1        | LOG:  autovacuum launcher shutting down
    db_1        | LOG:  shutting down
    webapp_1    | clock source: unix
    webapp_1    | pcre jit disabled
    webapp_1    | detected number of CPU cores: 1
    webapp_1    | current working directory: /
    webapp_1    | detected binary path: /usr/local/bin/uwsgi
    webapp_1    | setgid() to 108
    webapp_1    | setuid() to 104
    webapp_1    | chdir() to /srv/starter/
    db_1        | waiting for server to shut down....LOG:  database system is shut down
    webapp_1    | your processes number limit is 1048576
    webapp_1    | your memory page size is 4096 bytes
    db_1        |  done
    webapp_1    |  *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
    db_1        | server stopped
    webapp_1    | detected max file descriptor number: 1048576
    webapp_1    | lock engine: pthread robust mutexes
    webapp_1    | thunder lock: disabled (you can enable it with --thunder-lock)
    webapp_1    | uwsgi socket 0 bound to TCP address :8000 fd 3
    db_1        |
    webapp_1    | Python version: 3.4.4 (default, Jan 18 2016, 19:45:07)  [GCC 4.9.2]
    webapp_1    | Python main interpreter initialized at 0xb0c950
    db_1        | PostgreSQL init process complete; ready for start up.
    webapp_1    | python threads support enabled
    db_1        |
    webapp_1    | your server socket listen backlog is limited to 100 connections
    db_1        | LOG:  database system was shut down at 2016-01-25 03:38:08 UTC
    webapp_1    | your mercy for graceful operations on workers is 60 seconds
    db_1        | LOG:  MultiXact member wraparound protections are now enabled
    webapp_1    | mapped 496512 bytes (484 KB) for 20 cores
    db_1        | LOG:  database system is ready to accept connections
    webapp_1    | *** Operational MODE: preforking+threaded ***
    db_1        | LOG:  autovacuum launcher started
    webapp_1    | *** uWSGI is running in multiple interpreter mode ***
    webapp_1    | spawned uWSGI master process (pid: 16)
    webapp_1    | Mon Jan 25 03:41:12 2016 - [emperor] vassal /etc/uwsgi/django-uwsgi.ini has been spawned
    webapp_1    | spawned uWSGI worker 1 (pid: 17, cores: 10)
    webapp_1    | spawned uWSGI worker 2 (pid: 18, cores: 10)
    webapp_1    | unable to stat() /etc/uwsgi/reload-uwsgi.ini, events will be triggered as soon as the file is created
    webapp_1    | WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0xb0c950 pid: 18 (default app)
    webapp_1    | WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0xb0c950 pid: 17 (default app)
    webapp_1    | Mon Jan 25 03:41:13 2016 - [emperor] vassal /etc/uwsgi/django-uwsgi.ini is ready to accept requests
    

    And nmap test looks like 80 / 433 ports are closed:

    ➜  docker-django git:(master) nmap -Pn 192.168.99.100
    
    Starting Nmap 7.01 ( https://nmap.org ) at 2016-01-25 14:02 VLAT
    Nmap scan report for 192.168.99.100
    Host is up (0.0011s latency).
    Not shown: 998 closed ports
    PORT     STATE SERVICE
    22/tcp   open  ssh
    9080/tcp open  glrpc
    
    Nmap done: 1 IP address (1 host up) scanned in 1.18 seconds
    

    What I do wrong?

    opened by egregors 3
  • Asynchronous containers

    Asynchronous containers

    Because docker compose asynchronously starts the containers, it will happen that the db container isn't ready to accept connections when the app container wants to connect to it. This is reported as a caveat at the official postgres image repo.

    At the moment I solved this by using scripts that will check whether the db container is ready to accept connection. However I'd like to use a more elegant solution.

    So with the creation of this issue I want to investigate if this is possible and what I can use.

    enhancement 
    opened by jpbruinsslot 3
  • Nginx conf + envsubst issue

    Nginx conf + envsubst issue

    start.sh uses envsubst to replace environment variables in the nginx conf, but the nginx conf also contains variables that are not environment variables that are prefaced with a $ which means they get replaced with nothing. Specifically in the nginx.tmpl you are using this variable: $request_uri. When I get redirected from http to https I do not have my path preserved.

    This could work. By passing the variables it will not stomp on all the variables in nginx.tmpl envsubst $(compgen -v | grep NGINX* | sed 's/NGINX/$NGINX/' | tr "\n" ",") < nginx.tmpl > /etc/nginx/nginx.conf

    opened by tosborne1215 2
  • Error handling in DB check loop

    Error handling in DB check loop

    Do we really need this set -e call? I'm not sure on what systems the bash script will continue to the line 10, but for me, as per bash documentation, the script exits if first test (L10) exists with code 1.

    https://github.com/erroneousboat/docker-django/blob/4b9ee750776933c690e18074ce02981b88057290/webapp/config/start.sh#L9-L15

    Instead, I think we can keep using set -e and simplify the script with something like:

    set -e
    until python3 ./database_check.py; do
        sleep 5; echo "*** Waiting for postgres container ..."
    done
    echo "*** Postgres container available..."
    set +e
    
    opened by asfaltboy 1
  • Question about docker files

    Question about docker files

    Since I recently started working with docker, what is the purpose of having both

    ADD ./starter /srv/starter
    

    in the Dockerfile and

    volumes:
    - ./webapp/starter:/srv/starter
    

    in the docker-compose?

    opened by vinPopulaire 1
  • Multiple processes in one container

    Multiple processes in one container

    From the baseimage-docker documentation it states: "We encourage you to use multiple processes.". Does this also mean that it is advised postgresql to run postgres in the same container?

    opened by jpbruinsslot 1
  • Multi-project architecture, LetsEncrypt, Creator, nginx separation, simplification

    Multi-project architecture, LetsEncrypt, Creator, nginx separation, simplification

    Hello @erroneousboat,

    I found your project to be a good base for a proper, production-ready docker-compose django setup. I've made some changes to it - hopefully you'll see them as improvements. If you find they make sense to you, feel free to pull this.

    • [x] separated nginx into its own service
    • [x] the above removed the need for init-based containers, and ssh - everything simplified
    • [x] made use of latest docker-compose 1.5 features that makes it possible build on top of existing .yml's
    • [x] implemented automated LetsEncrypt for hassle-free valid and free SSL certificates (will work from November 16, 2015)
    • [x] project-independent architecture - multiple projects can be started with the same docker images (pip install on first run instead of in-image)
    • [x] this also means you don't need to clone this project for every new Django project, making it more maintainable
    • [x] added a project configuration creator (./create) - generates .yml override files
    • [x] added an alias for issuing commands relevant to a specific project (./compose PROJECT_NAME)
    • [x] removed the need for the heavy template binary, opting to use sed instead
    • [x] updated readme
    opened by niieani 0
Owner
JP Bruins Slot
JP Bruins Slot
A test Django application with production-level docker setup

DockerApp A test Django application with production-level docker setup. Blog: https://medium.com/@siddharth.sahu/the-near-perfect-dockerfile-for-djang

Siddharth Sahu 44 Nov 18, 2022
Um template para quem quiser usar o Docker + PGSQL + Django.

Um template para quem quiser usar o Docker + PGSQL + Django.

Drack 2 Mar 11, 2022
Get a Django app up and running in dev, test, and production with best practices in 10 minutes

Django template for Docker + Heroku This is how I set up Django projects to get up and running as quick as possible. In includes a few neat things: De

Ben Firshman 30 Oct 13, 2022
Brif is a boilerplate tool based on Docker and FastAPI, designed to streamline the development and deployment of IIIF compliant platforms.

brif A boilerplate tool based on Docker, designed to streamline the development and deployment of IIIF compliant platforms. Embedded with FastAPI, Cel

Pierre 8 Sep 17, 2022
Basic Docker Compose template application with Flask, Celery, Redis, MySQL, SocketIO, Nginx and Gunicorn.

Nginx / Gunicorn / Flask ?? / Celery / SocketIO / MySQL / Redis / Docker ?? sample application Basic Docker Compose template application for orchestat

Alex Oarga 8 Aug 6, 2022
Vue + Django with no compromises. Django Templates and Vue SFCs in harmony without sacrificing the full power of either.

Cookiecutter Vue Django Vue + Django with no compromise. Cookiecutter Vue Django is a framework for jumpstarting production-ready Django + Vue project

Mike Hoolehan 122 Dec 22, 2022
simple flask starter app utilizing docker

Simple flask starter app utilizing docker to showcase seasonal anime using jikanpy (myanimelist unofficial api).

Kennedy Ngugi Mwaura 5 Dec 15, 2021
Django sample app with users including social auth via Django-AllAuth

demo-allauth-bootstrap Simple, out-of-the-box Django all-auth demo app A "brochure" or visitor (no login required) area A members-only (login required

Andrew E 215 Dec 20, 2022
Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

Cookiecutter Django Powered by Cookiecutter, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. Documentati

Daniel Roy Greenfeld 10k Jan 1, 2023
Django Webpack starter template for using Webpack 5 with Django 3.1 & Bootstrap 4. Yes, it can hot-reload.

Django Webpack Starter Hello fellow human. The repo uses Python 3.9.* Django 3.1.* Webpack 5.4.* Bootstrap 4.5.* Pipenv If you have any questions twe

Ganesh Khade 56 Nov 28, 2022
A Django project skeleton that is modern and cutting edge.

{% comment "This comment section will be deleted in the generated project" %} Edge A Fantastic Django project starter. Features Ready Bootstrap-themed

Arun Ravindran 827 Dec 15, 2022
Django starter project with 🔋

A batteries-included Django starter project. For a production-ready version see the book Django for Professionals. ?? Features Django 3.1 & Python 3.8

William Vincent 1.5k Jan 8, 2023
Project template layout for Django 3.0+

Django 3.0+ project template This is a simple Django 3.0+ project template with my preferred setup. Most Django project templates make way too many as

José Padilla 649 Dec 30, 2022
Django project/application starter for lazybones :)

Django Project Starter Template My custom project starter for Django! I’ll try to support every upcoming Django releases as much as I can! Requirement

Uğur Özyılmazel 40 Jul 16, 2022
Starter project for python based lambda project.

Serverless Python Starter Starter project for python based lambda project. Features FastAPI - Frontend dev with Hot Reload API Gateway Integration (+r

null 4 Feb 22, 2022
Bleeding edge django template focused on code quality and security.

wemake-django-template Bleeding edge django2.2 template focused on code quality and security. Purpose This project is used to scaffold a django projec

wemake.services 1.6k Jan 4, 2023
Bleeding edge django template focused on code quality and security.

wemake-django-template Bleeding edge django2.2 template focused on code quality and security. Purpose This project is used to scaffold a django projec

wemake.services 1.6k Jan 8, 2023
Combine the power of FastAPI and Django to build a production-ready application capable of utilizing all of the best features of both worlds.

FastAPI and Django Combo This projects aims to combine FastAPI and Django to build a Production ready application capable of utilizing all of the feat

Nsikak Imoh 33 Dec 27, 2022
This is a boilerplate for a basic backend app using Python, Django and SQLite, as developed after tutorials with Programming with Mosh

This is a boilerplate for a basic backend app using Python, Django and SQLite, as developed after tutorials with Programming with Mosh

Gustavo Catala Sverdrup 1 Jan 7, 2022