Setup a Postgres Database With Docker Compose

Adding a Postgres database to an existing service is fairly straightforward with docker-compose. Create a Dockerfile for your main service. For example, here’s a simple Docker container with Node: FROMnode:12.14.0-alpine3.9ENV NPM_CONFIG_PREFIX=/home/node/.npm-globalRUN npm install npm@latest -g –silentWORKDIR/opt/appCOPY package*.json /opt/app/RUN npm install –no-optional && npm cache clean –forceENV PATH /opt/app/node_modules/.bin:$PATHENV PATH=$PATH:/home/node/.npm-global/binARG NODE_ENV=production ENV NODE_ENV $NODE_ENVARG PORT=3000 ENV PORT $PORTEXPOSE$PORT 8229 8230COPY . .CMD ["npm", "run", "watch"]The Dockerfile starts from the official Node container, updates npm globally, installs the necessary packages, and runs an npm command (as root user in development mode).
Read more →

2019 Week 50: A Look Back

Read more →

Friday Picks 029

Read more →

Example Multi Stage Docker Build for React

I’m still trying to improve my Docker builds. Here’s an example for a multi-stage Docker build for React:

base imageFROMnode:12.13.1-alpine as compile-image## install global packagesENV NPM_CONFIG_PREFIX=/home/node/.npm-globalRUN npm install npm@latest -gRUN npm install pnpm react-scripts@3.3.0 -g## set working directory & give permissions to user nodeRUN mkdir -p /usr/src/app && chown node:node /usr/src/appWORKDIR/usr/src/app## switch to non-root user & install dependenciesUSERnodeCOPY package*.json /usr/src/app/COPY pnpm-lock.yaml /usr/src/app/pnpm-lock.yamlENV PATH /usr/src/app/node_modules/.bin:$PATHENV PATH=$PATH:/home/node/.npm-global/binRUN pnpm install## set environment to production, overwrite## with docker-composeARG NODE_ENV=production ENV NODE_ENV $NODE_ENV## create buildCOPY .

Read more →

Learning About Best Practices for Docker and Node

Today I’ve tried to update one of my Docker apps that uses React, Enzyme, and Jest. This lead me on a wild goose chase about react-test-renderer and best practices for Docker builds for Node.js. I’m still not sure where the problem is (Enzyme, maybe?). But I found three useful resources for Docker and Node.js: Docker and Node.js Best Practices Node + Docker Hello World, for Showing Good Defaults for Using Node.
Read more →

Wrangling With Docker

I’m currently wrangling with Docker. I’m working through some Docker courses on Udemy and Sitepoint. Plus, I’m reading articles on how to improve my Docker files. I like playing with tools like Docker and docker-compose. But they add a lot of complexity to an application. Here are some useful links and resources about Docker: Advanced multi-stage build patterns by Tõnis Tiigi 9 Common Dockerfile Mistakes by Jorge Silva Production-ready Docker packaging Docker for Node.
Read more →

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 →

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 →