📎 Webclip
Deploying a Phoenix app with Dokku
The page walks through deploying a Phoenix blog app on Dokku, starting with a VPS setup and a Dokku installation on Ubuntu. It then shows how to create the app, set environment variables, connect a Postgres database, and configure buildpacks so Elixir and frontend assets compile during deploy.
Reading notes#
- Dokku is presented as the preferred way to deploy a web app to a VPS, with a Heroku-style workflow based on pushing code with git.
- The example app is an Elixir + Phoenix + Ecto blog connected to Postgres.
- The server setup uses a $5/month DigitalOcean VPS with Ubuntu 18.04 and a 1GB swap file to help node compile frontend dependencies.
- Dokku is installed over SSH with the bootstrap script from the Dokku release.
- The web installer is used to set the hostname and enable user virtual naming for apps, which allows subdomain access.
- The blog subdomain is pointed to the Dokku server’s IP address.
- A Dokku app named
blogis created, andLC_ALL,MIX_ENV, andSECRET_KEY_BASEare set as environment variables. - The Postgres plugin is installed, then a
blogdatabase is created and linked to the app. - Linking Postgres exports
DATABASE_URL, which Phoenix already expects. - A local git remote named
dokkuis added so the repository can be deployed withgit push dokku master. - The repo needs
.buildpacksplus Elixir, Erlang, and Node version files so Dokku can build the app correctly. - After the first push, the app should run on the server IP or on the configured subdomain.
- Ecto migrations are still required: the database is created with
dokku run mix ecto.create, and anapp.jsonfile setsmix ecto.migrateas the postdeploy command. - A custom domain can be added with
dokku domains:add blog <your-fancy-domain>. - SSL is enabled with the Dokku letsencrypt plugin, which also sets up auto-renewal.
