image from the Gotify website You have several devices and you want to receive notifications from your Android phone to your web browser (or vice versa). Maybe you also want to send notifications via REST API. You are a developer after all. You can think of interesting ways to send notifications. Pushbullet comes to mind, but you don’t want to sign up with Google or Facebook. You don’t want to use Google services.
Sandbox your React Native development Expo CLI is a tool to install and run React Native applications. Expo is a toolchain that claims to be “the fastest way to build an app”. You can install those tools on your local machine. But maybe you want to create a stand-alone development environment using Docker containers. That way you can be sure of a consistent development environment across different machines.
Today I tried to create a docker secret for a Docker Swarm stack. Why? The secret is encrypted and you cannot read it. I’ve used environment variables before, but they are stored as plain text. You can see them if you inspect the Docker service/image. It took me a while to figure out how to use docker secrets with a docker-compose.yml. You can use Docker secrets both locally (docker-compose up) and for production (docker stack deploy).
Advanced Traefik 2 Setup with Docker Swarm, SSL Certificates and Security Options Traefik is an open-source router and load-balancer that sits in front of your web services. You can set it up to automatically encrypt your websites with SSL certificates. It’s also easy to add new web services to an existing Traefik cluster. I discovered Traefik via Jakub Svehla’s post Building a Heroku-like infrastructure for $5 a month. He shows you how to use Docker to install a Traefik infrastructure on a cheap VPS like DigitalOcean.
Today I learned that you can use Makefiles to create simple task-runners. Stuart Feldman invented Make in 1976 to automate build processes for C programs. But you can use it for other languages, too. For example, Vladislav Supalov uses this Makefile for Docker commands: all: @echo "Usage: build or run" build: docker build -t test . run: docker run --rm -it test Now run the file with your terminal: make > Usage: build or run Build the Docker container via make build or run the container via make run.
(image by @mamihery) Why Hy? My second programming language was a Lisp. I fell in love with the expressiveness of Lisps. But most Lisps are obscure. The ecosystem is not suited for beginners. One of younger Lisps, Clojure, was my first foray into the world of web-development. I failed spectacularly because I didn’t know how web-develoment worked, and the Clojure ecosystem assumes too much previous knowledge. Other languages, e.g., Racket, are more approachable, but are still too unpopular to have a big community.
The Zero To Mastery Deno Course deploys a Deno docker container to Amazon EC2. The EC2 instances cost money after you’ve exhausted your free 12 months. Plus, Amazon’s cloud services can be tricky. Sometimes, services spike. You quickly exceed your free tier, even for a simple toy app. Let’s deploy Deno to Heroku instead. Heroku’s free tier stays free regardless of usage. The free level is slow, because it will periodically stop to save resources.
Quickly Add MongoDB to Your App With Docker MongoDB is an open-source NoSQL database that stores data in JSON-like documents. NoSQL databases are a natural choice if you don’t know your data requirements upfront. They are also a good fit for applications like product catalogs or blog content. That’s where an object-oriented approach shines. Let’s see how we can easily add a Mongo database with Docker and Docker Compose.
I prefer to use Docker containers for running a PostgreSQL database. Spin up the container, develop the app, then tear down the container. The Postgres database doesn’t clutter up my local system, and I can easily set it up on a different machine. Using Docker Compose, I can configure the setup and commit it to source control. In this blog post, I’ll show you how to get a database up and running with Docker and Docker Compose.
Three days ago I started a short tutorial on how to write a test-driven Node.js web API with PostgreSQL database. The excellent blog post is from 2016, but it’s still useful. I used Docker to build the application. If you want to see the example application as a dockerized Node.js/Express.js program, you can take a look at my GitLab repository. The repository also uses GitLab CI to build the container and run the tests with Mocha.
Project Structure Here’s the project structure for my application. Adjust to your needs. I used the Express application generator to scaffold the program. . ├── docker-compose.yml ├── Dockerfile ├── healthcheck.js ├── LICENSE ├── node_app │ ├── app.js │ ├── bin │ │ └── www │ ├── db │ │ ├── Dockerfile │ │ ├── knex.js │ │ ├── migrations │ │ └── seeds │ ├── knexfile.js │ ├── node_modules │ ├── package.
Create a Docker container that runs your machine learning models as a web application This article will explain the advantages of Streamlit and how to build a Streamlit application with Docker. Why Streamlit? You’ve explored your data and developed a machine learning model. It’s now time to release it to the world so that others can see what you’ve built. Now what? Deploying machine learning models is not trivial.
Let Docker access the internet by passing through the VPN connection strongSwan My host machine, a laptop running Manjaro Linux, is connected via VPN to the internet. I use strongSwan, the open-source IPsec-based VPN solution. IPsec with the IKEv2 protocol is fast and secure. Now, Docker doesn’t work. Networking issues are a common problem with VPN and Docker. You can piggyback your Docker container on the host network. That technique only works on Linux machines.
Docker builds containers via layers. All commands add another layer to the already existing image. What does that mean for changing file permissions via chown or chmod? Let’s say we build this image: FROMfrolvlad/alpine-miniconda3:python3.7 AS build## set working directoryWORKDIR/usr/src/app## copy codeCOPY ./code /codeCOPY ./notebooks /notebooks## add non-root userRUN addgroup --system user && \ adduser --system -G user user && \ chown -R user:user /usr/src/appAfter copying the code from the host machine to the container, we switch permissions for the working directory from root to user.
Today I’ve spent all my coding time on re-factoring my sqlite3 database to postgres. Nim and Jester (a web framework) ship with inbuilt sqlite3 features. I couldn’t get them working within Docker. I know how to use Docker and Postgres. Plus, the wrapper library for Nim around SQL databases offers a consistent API. My re-factoring only needed minimal changes. The project is still in flux. And I have some annoying errors with Nim and SQL queries.
Today I learned that you can’t bind-mount folders on your host machine into a Docker container during build. For local development, I bind-mount with docker-compose. Example: version: '2.4'services: url-shortener: build: context: ./services/url-shortener dockerfile: Dockerfile volumes: - './services/url-shortener:/usr/src/app:delegated' ports: - 5001:5000My goal was to use the language’s package manager to install the required dependencies. Here’s the Dockerfile: ## base imageFROMnimlang/nim:1.0.4-regular AS build-image## set working directoryWORKDIR/usr/src/app## install dependenciesRUN nimble refresh && nimble install -y## run serverCMD nimble c -r src/urlShortenerHere is the problem: nimble can’t find the required files for installation.
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.
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 email@example.com -g## set working directory & give permissions to user `node`RUN 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 .
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.
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.
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.
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).
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):
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.
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.
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 firstname.lastname@example.org -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.
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: ## base image FROM python:3.
Today I reviewed my progress with the Microservices with Docker, Flask, and React by Michael Herman. I’m not familiar with Flask, but I wanted to learn how to build a microservices app with TDD. The testdriven.io course was the best course I could find which uses Docker, and React and teaches testing principles. The parts about Docker proved already useful. I used the setup to dockerize a simple Django app.
I’m trying to use Docker for my apps. I like the tool, and it also helps to have a stable dev environment when everything runs inside a container. But it adds another layer of complexity. Now, a lot goes wrong with trying to set up Docker, docker-compose, etc. correctly. Luckily, I’m happy to fiddle with tools (would I be using Vim, Colemak, Arch Linux otherwise?). The free preview of the Microservices with Docker, Flask, and React should give you an overview of how to use Docker with Python.
Today I tried to set up a dockerized Flask app with Postgres database with Travis CI. It shouldn’t have been difficult because I followed a tutorial. Setup Here is the docker-compose.yml: version: '3.7' services: users: build: context: ./services/users dockerfile: Dockerfile volumes: - './services/users:/usr/src/app' ports: - 5001:5000 environment: - FLASK_ENV=development - APP_SETTINGS=project.config.DevelopmentConfig - DATABASE_URL=postgres://postgres:postgres@users-db:5432/users_dev - DATABASE_TEST_URL=postgres://postgres:postgres@users-db:5432/users_test depends_on: - users-db users-db: build: context: ./services/users/project/db dockerfile: Dockerfile ports: - 5435:5432 environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres nginx: build: context: .
I try to learn something new every day, and I find it surprising what cool things you can do with technology. Today I learned that you could run a PostgreSQL database in a docker container. I was doing a Phoenix tutorial by Alvise Susmel. The article shows you how to create a Phoenix app which can handle user uploads and is an interesting piece in itself. But I also like the idea of running the database in Docker for local development.