A few days ago, I created a Docker build for Flask with PostgreSQL (both with Alpine Linux and with Debian Linux). Installing psypcopg-2 binary (required for Postgres) requires you to build the package from source. Now the Docker image grows in size, as it still contains the build artifacts. The solution? Multi-stage Docker builds. Let’s say we have the following docker-compose.yml file. There are two services: a Flask API called users and a Postgres database called users-db.
Create isolated Python projects with virtual environments What is a virtual environments and why should I use it? A virtual environment allows you to develop several Python projects with different versions of packages on the same computer. Python usually installs the latest versions of your dependencies globally. You’ll run into problems, if one of your projects requires a different package version. venv Python ships with venv out of the box since version 3.
How to build a Python app with PostgreSQL I’m currently setting up a Flask app with PostgreSQL and Docker. Like most examples you’ll find on the internet, the course I’m following uses Alpine Linux as a base image. Alpine’s selling point is the small image size. But Alpine uses a different C library, musl, instead of glibc. That’s one of the reasons why the website Pythonspeed recommends Debian Buster as the base image for Python (as of 2019).
I started the Microservices with Docker, Flask, and React a while ago. The course proved to be quite challenging, as I’m not familiar with Docker and Flask. It also uses advanced features of React. It was very fascinating for me to see how to develop a modern application with TDD, using Docker. While the React part is a bit outdated (it still uses deprecated methods like getDerivedState) - everything works and teaches you useful concepts.