Using Docker

If you want to try out the django-base-site using Docker then you first need to install docker. Then you can go through the following steps.

  1. First download the django-base-site wherever you want your new project.
$ TARGET_DIR=~/Sites/ BRANCH=master PROJECT_NAME=example && \
cd $TARGET_DIR && \
curl -L "https://github.com/epicserve/django-base-site/archive/$BRANCH.zip" | tar zx -C $TARGET_DIR && mv "django-base-site-$BRANCH" $PROJECT_NAME &&  \
cd $PROJECT_NAME
  1. Create your .env file.
$ export SECRET_KEY=$(python -c "import random; print(''.join(random.SystemRandom().choice('abcdefghijklmnopqrstuvwxyz0123456789%^&*(-_=+)') for i in range(50)))") && \
cat > .env <<EOF
DEBUG=on
DATABASE_URL=postgres://postgres@db:5432/postgres
SECRET_KEY='$SECRET_KEY'
EMAIL_HOST='smtp.planetspaceball.com'
EMAIL_HOST_USER='skroob@planetspaceball.com'
EMAIL_HOST_PASSWORD='12345'
DEFAULT_FROM_EMAIL="President Skroob <skroob@planetspaceball.com>"
ALLOWED_HOSTS=*
INTERNAL_IPS=192.168.99.100,127.0.0.1,0.0.0.0,localhost,172.18.0.1
REDIS_HOST=redis
EOF
  1. Build your service images.
$ docker-compose build
  1. Run migrations and Create a super user.
$ docker-compose run web python manage.py migrate && \
docker-compose run web python manage.py createsuperuser
  1. Run the Django runserver.
$ docker-compose up

Debugging

ipdb

Set a trace like you normally do in your code and then go to that view in your browser and then stop docker-compose up.

import ipdb; ipdb.set_trace()

Then you can run the following to work interactive debugging shell.

docker-compose run --service-ports web

PyCharm

Running Gulp

  • When you run docker-compose up it starts the node service which should run gulp.
  • If you want to run gulp by itself, you can run it with a command like, docker-compose run --rm node.

Common Gotchas

  • You need to start your runserver using docker-compose up instead of docker-compose run web python manage.py runserver 0.0.0.0:8000 or you won’t be able to access your site from your browser.
  • Installing django-debug-toolbar can ignore the Django version you’ve specified in your Pipfile and instead Django 2 because django-debug-toolbar uses “Django” with a capital D in it’s requirements when other packages use “django” in lowercase. To work around this install everything except django-debug-toolbar and then added it last to your Pipfile.

Common Commands

Command Description
docker-compose up Starts up all of your services according to how they were defined in your docker-compose.yml file.
docker-compose down Stops containers and removes containers, networks, volumes, and images created by up.
docker volume ls List the volumes that have been created