Tutorial: Dockerizing Flask with Postgres, Gunicorn, and Nginx
- Configure Flask to run on Docker with Postgres;
- Add Nginx and Gunicorn for production environment;
- Serve static and user-uploaded media files via Nginx;
- Build the images and run the containers:
$ docker-compose up -d --build
$ docker-compose -f docker-compose.prod.yml up -d --build
$ docker-compose -f docker-compose.prod.yml exec web python manage.py create_db
- Bring down containers
docker-compose down -v
-
Ensure App is running http://localhost:1337
-
Upload Asset http://localhost:1337/upload.
-
View Asset http://localhost:1337/media/IMAGE_FILE_NAME.
- Set up a fully managed database service -- like RDS or Cloud SQL -- rather than managing your own Postgres instance within a container.
- Use a non-root user for the db and nginx services for security reasons