flask-on-docker icon indicating copy to clipboard operation
flask-on-docker copied to clipboard

Flask + Docker

Dockerizing Flask with Postgres, Gunicorn, and Nginx

Want to learn how to build this?

Check out the post.

Want to use this project?

Development

Uses the default Flask development server.

  1. Rename .env.dev-sample to .env.dev.

  2. Update the environment variables in the docker-compose.yml and .env.dev files.

    • (M1 chip only) Remove -slim-buster from the Python dependency in services/web/Dockerfile to suppress an issue with installing psycopg2
  3. Build the images and run the containers:

    $ docker-compose up -d --build
    

    Test it out at http://localhost:5000. The "web" folder is mounted into the container and your code changes apply automatically.

Production

Uses gunicorn + nginx.

  1. Rename .env.prod-sample to .env.prod and .env.prod.db-sample to .env.prod.db. Update the environment variables.

  2. Build the images and run the containers:

    $ docker-compose -f docker-compose.prod.yml up -d --build
    

    Test it out at http://localhost:1337. No mounted folders. To apply changes, the image must be re-built.