📎 Webclip
Deploying with Releases — Phoenix v1.8.16
The guide shows how to turn a Phoenix application into a self-contained release that can be copied to a production machine. It also covers how to run database migrations and other commands from inside the release, how to build container images from the release artifacts, and how to set up clustering.
Reading notes#
- The goal is to package a Phoenix app with the Erlang VM, Elixir, code, and dependencies in one directory that can be deployed to production.
- To prepare a release, the guide uses environment variables, installs production dependencies, compiles code and assets, and then runs
mix phx.gen.releasefollowed bymix release. phx.gen.releasecreates overlay scripts for starting the server and running migrations, plus arelease.exfile for invoking Ecto migrations withoutmix.- The generated release can be started, opened remotely, stopped, or inspected through the release’s command scripts.
- For migrations, the guide defines
MyApp.Release.migrate/0androllback/2, then calls them through the releaseevalcommand. - The same pattern can be used for custom production commands, with
load_appfor loading the app andensure_all_startedwhen the command needs the full supervision tree. - Docker support comes from
mix phx.gen.release --docker, which generates a Dockerfile that builds the release inside a builder image and copies the result into a smaller runtime image. - Runtime configuration should be kept in
config/runtime.exs, especially secrets and environment-specific values, so images stay reusable across environments. - The clustering section explains two needs for node clustering: node connection and service discovery.
- For DNS-based clustering, the guide suggests configuring ports and node names in
rel/env.sh.eexand settingDNS_CLUSTER_QUERYto find peer instances. - If DNS discovery is not available, the guide points to
libclusterandlibcluster_postgresas alternative discovery mechanisms. - For
epmd-less deployment, the guide replaces the default port setup withrel/vm.args.eexandrel/remote.vm.args.eex, exposing only a fixed distribution port besides HTTP.
