How to Deploy Elixir to Docker Without Writing a Dockerfile
You can containerize any Elixir application without writing a Dockerfile using migetpacks. It auto-detects your Elixir and Erlang versions from .tool-versions or .elixir-version, builds Mix releases for production, automatically compiles Phoenix assets, and produces an optimized production image. One command, zero configuration.
Why Is Writing a Dockerfile for Elixir So Complicated?
A production-ready Elixir Dockerfile requires:
- Multi-stage builds to separate build from runtime
- Installing Hex and Rebar before dependencies
- Proper Mix release configuration
- Phoenix asset compilation with esbuild
- Erlang/OTP version compatibility with Elixir
- Handling umbrella projects correctly
MIX_ENV=prodfor production builds
Get Erlang version compatibility wrong and your release won't start. Skip asset compilation and your Phoenix app has no CSS/JS.
How Do I Containerize an Elixir App Without a Dockerfile?
Open your terminal, navigate to your Elixir project, and run:
cd ~/projects/my-phoenix-app
docker run --rm \
-v "$PWD":/workspace/source \
-v /var/run/docker.sock:/var/run/docker.sock \
-e OUTPUT_IMAGE=my-phoenix-app:latest \
miget/migetpacks:latest
That's it. migetpacks will:
- Detect Elixir from
mix.exs - Read versions from
.tool-versions,.elixir-version, or.erlang-version - Install Hex and Rebar
- Run
mix deps.getwith caching - Compile Phoenix assets if detected
- Build a Mix release
- Output a slim production image
How Does migetpacks Detect Versions?
Elixir Version
| Source | Example |
|---|---|
.elixir-version | 1.18.4 |
.tool-versions (asdf) | elixir 1.18.4 |
| Default | Latest stable |
Erlang/OTP Version
| Source | Example |
|---|---|
.erlang-version | 27.0 |
.tool-versions (asdf) | erlang 27.0 |
| Default | Auto-compatible with Elixir version |
If no Erlang version is specified, the Elixir Docker image's bundled Erlang/OTP version is used.
What Does the Generated Dockerfile Look Like?
# Build stage
FROM elixir:1.18.4 AS builder
WORKDIR /build
ENV MIX_ENV=prod
ENV ERL_FLAGS="-noinput"
COPY mix.exs mix.lock* ./
COPY config ./config/
RUN mix local.hex --force \
&& mix local.rebar --force \
&& mix deps.get --only prod
RUN mix deps.compile
COPY . .
RUN mix compile
RUN mix release
# Runtime stage
FROM elixir:1.18.4-slim
WORKDIR /app
COPY --from=builder --chown=1000:1000 /build /app
You never write or maintain this file - migetpacks handles it automatically.
How Does Phoenix Asset Compilation Work?
If mix.exs contains a :phoenix dependency, migetpacks automatically:
- Copies
config/early (needed for dependency compilation) - Compiles assets using
mix assets.deploy - Falls back to npm-based asset pipeline if needed
- Runs
mix phx.digestfor static file fingerprinting
No configuration needed.
Does migetpacks Support Mix Releases?
Yes. migetpacks detects if the project uses Mix releases by checking for releases: in mix.exs. When releases are used:
- The release binary is self-contained (no Hex/Mix needed at runtime)
- The runtime image is slimmer
- The run command uses the release binary:
/app/bin/{app_name} start
What Run Command Is Used?
| Configuration | Default Command |
|---|---|
| With releases | /app/bin/{app_name} start |
| Without releases (Phoenix) | mix phx.server |
| Without releases (plain) | mix run --no-halt |
Does migetpacks Support Umbrella Projects?
Yes. If an apps/ directory exists, migetpacks detects an umbrella project and copies child mix.exs files for proper dependency resolution.
How Do I Run a Phoenix App?
Phoenix requires SECRET_KEY_BASE at runtime. Generate one with mix phx.gen.secret:
# Build the image
cd ~/projects/my-phoenix-app
docker run --rm \
-v "$PWD":/workspace/source \
-v /var/run/docker.sock:/var/run/docker.sock \
-e OUTPUT_IMAGE=my-phoenix:latest \
miget/migetpacks:latest
# Run with required environment variables
docker run -p 4000:4000 \
-e SECRET_KEY_BASE=$(mix phx.gen.secret) \
-e DATABASE_URL=ecto://user:pass@host/db \
my-phoenix:latest
Next Steps
- Full Elixir documentation - version detection, Phoenix, releases
- Deploy on Miget - unlimited apps, one price
- Star on GitHub - migetpacks is open source
- Related guides: Ruby, Python