The last fews day's I've been learning how to deploy a Flask and React application to AWS. I've decided to shelf that project for now. As a hobby developer and learner I don't need all the features that AWS offers. A setup with Load Balancer, RDS instances, etc. adds a lot of complexity which I have no use for. The plan for this month was to create a test-driven Python and React application.
How to run nginx as non-privileged user with Docker nginx is an open-source solution for web serving and reverse proxying your web application. You put it “in front” of your different services, and nginx can route the traffic to the correct url. That's useful for micro-services, for example. Per default, nginx runs as root user. Why? Only root processes can listen to ports below 1024. The default port for web applications is usually 80 or 443.
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).
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 firstname.lastname@example.org -g# set working directory & give permissions to user