fix(Docker): Fixed Docker-Compose-Example

The docker-compose example now runs out of the box. Migrations are
applied at startup and cachetable is created.

Closes #141
This commit is contained in:
MaximilianKindshofer 2020-04-18 18:28:51 +02:00
parent 8898a04edf
commit 85777d0b9a
3 changed files with 10 additions and 13 deletions

View File

@ -106,14 +106,6 @@ and set, at least, the `ALLOWED_HOSTS` and `SECRET_KEY` variables under
docker-compose up -d docker-compose up -d
1. Initialize the database *(first run/after migrations updates)*
docker-compose exec app python manage.py migrate
1. Initialize cache table *(first run/after cache configuration updates)*
docker-compose exec app python manage.py createcachetable
The app should now be locally available at The app should now be locally available at
[http://127.0.0.1:8000](http://127.0.0.1:8000). See [http://127.0.0.1:8000](http://127.0.0.1:8000). See
[Docker's "Get Started" documentation](https://docs.docker.com/get-started/) [Docker's "Get Started" documentation](https://docs.docker.com/get-started/)

View File

@ -9,6 +9,7 @@ DATABASES = {
'ENGINE': 'django.db.backends.postgresql_psycopg2', 'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres', 'NAME': 'postgres',
'USER': 'postgres', 'USER': 'postgres',
'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),
'HOST': 'db', 'HOST': 'db',
'PORT': 5432, 'PORT': 5432,
} }

View File

@ -1,22 +1,26 @@
version: "3.7" version: "3.7"
services: services:
db: db:
image: postgres image: postgres:11 # pin postgres to a major version
environment: environment:
- PGDATA=/db-data - PGDATA=/db-data
- POSTGRES_PASSWORD=postgres # has to correspond with POSTGRES_PASSWORD in APP
volumes: volumes:
- db:/db-data:rw - db:/db-data:rw
app: app:
image: babybuddy/babybuddy image: babybuddy/babybuddy
# See README.md#configuration for other environment configuration options. # See README.md#configuration for other environment configuration options.
environment: environment:
- ALLOWED_HOSTS= - ALLOWED_HOSTS=*
- DJANGO_SETTINGS_MODULE=babybuddy.settings.docker - DJANGO_SETTINGS_MODULE=babybuddy.settings.docker
- SECRET_KEY= - SECRET_KEY=5
- TIME_ZONE= - TIME_ZONE=Europe/Berlin
- POSTGRES_PASSWORD=postgres
- DEBUG=False # Turn to False in production
volumes: volumes:
- media:/app/media:rw - media:/app/media:rw
command: gunicorn -c /app/gunicorn.py babybuddy.wsgi # Sleep 5 seconds to allow the db to to come up;
command: bash -c 'sleep 5 && python manage.py migrate --noinput && python manage.py createcachetable && python manage.py collectstatic --noinput && gunicorn babybuddy.wsgi -b :8000 --log-level=info'
ports: ports:
- "8000:8000" - "8000:8000"
depends_on: depends_on: