Create a Multi-Stage Docker Build for Python Flask and Postgres

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.
Read more →

Install psycopg2-binary With Docker

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).
Read more →

Decked Out With Black Friday Swag

Read more →

Dockerize a React App

This post will be my notes on dockerizing a React application. You can find the original post by Michael Herman at Dockerizing a React App. I use a dedicated node user in my approach, instead of running the container as root user. For detailed explanations, go to Michael’s post. Requirements Docker v19.03 docker-compose 1.25 Node v12.13.1 Project Setup Create the application, for example, via create-react-app: npx create-react-app dockerized-react && cd dockerized-react Docker Add a Dockerfile to your project directory (a file without extension):
Read more →

Sale: Microservices with Docker, React, Flask

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.
Read more →

TIL: Docker Python Connection Refused

Read more →

Docker NGinx 405 POST Not Allowed

Today it took me over one hour to debug an error with Docker and Nginx. Every time I tried to submit a form with a POST method, NGinx gave me a 405 error: “405 Not Allowed”. I originally thought that Nginx overrode React Router settings and tried to troubleshoot my production NGinx config. StackOverflow had some ideas: POST request not allowed - 405 Not Allowed - nginx, even with headers included.
Read more →

Remove Docker Containers And More

Read more →

Permission Denied When Installing NPM Packages With Docker

I have the following Dockerfile for a React app:

base image FROM node:11.12.0-alpine # set working directory WORKDIR /usr/src/app # add /usr/src/app/node_modules/.bin to $PATH ENV PATH /usr/src/app/node_modules/.bin:$PATH # install and cache app dependencies COPY package.json /usr/src/app/package.json COPY package-lock.json /usr/src/app/package-lock.json RUN npm install react-scripts@3.0.1 -g –silent RUN chown -R node:node . USER node RUN npm ci # start app CMD ["npm", "start"] After setting up the work directory I copy the package.

Read more →

Run Docker-compose as Root User: Python Coverage Permission Denied

I’m learning test-driven development with the course Microservices with Docker, Flask, and React. It’s been a lot of fun. I’ve also learned more about using Docker and docker-compose. The course uses Coverage.py for measuring Python code coverage. However, Coverage.py and Docker don’t play well with each other if you run the Docker container as a normal (non-root) user. PermissionError: [Errno 13] Permission denied: ‘usr/src/app/.coverage’ Here is the Dockerfile:
Read more →