diff --git a/Dockerfile b/Dockerfile
index 51c875cd6559cb7919bb08ffd5e6162f231f8667..e1e843b03a368c0afc82e41381d1a27de34c0b73 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -10,12 +10,18 @@ ENV PYTHONUNBUFFERED 1
 
 # install dependencies
 RUN apt-get -y update
-RUN apt-get install -y python python-pip python-dev python-django-extensions postgresql-client
+RUN apt-get install -y python python-pip python-dev python-django-extensions postgresql-client netcat
 RUN pip install --upgrade pip
 COPY ./requirements/production.txt /usr/src/app/requirements.txt
 RUN pip install -r requirements.txt
 
 RUN apt-get -y update && apt-get -y autoremove
 
+# copy entrypoint.sh
+COPY ./src/entrypoint.sh /usr/src/app/entrypoint.sh
+
 # copy project
-COPY ./src /usr/src/app/
\ No newline at end of file
+COPY ./src /usr/src/app/
+
+# run entrypoint.sh
+ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
\ No newline at end of file
diff --git a/src/entrypoint.sh b/src/entrypoint.sh
new file mode 100755
index 0000000000000000000000000000000000000000..08fe051b9daffce26a731f3e710e4455abf047ca
--- /dev/null
+++ b/src/entrypoint.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+if [ "$DATABASE" = "postgres" ]
+then
+    echo "Waiting for postgres..."
+
+    while ! nc -z $DB_HOST $DB_PORT; do
+      sleep 0.1
+    done
+
+    echo "PostgreSQL started"
+fi
+
+python manage.py flush --no-input
+python manage.py migrate
+
+exec "$@"
\ No newline at end of file