How to Deploy Elixir to Docker Without Writing a Dockerfile

M
Miget Team
Writer
January 8, 2026
5 min read

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=prod for 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:

  1. Detect Elixir from mix.exs
  2. Read versions from .tool-versions, .elixir-version, or .erlang-version
  3. Install Hex and Rebar
  4. Run mix deps.get with caching
  5. Compile Phoenix assets if detected
  6. Build a Mix release
  7. Output a slim production image

How Does migetpacks Detect Versions?

Elixir Version

SourceExample
.elixir-version1.18.4
.tool-versions (asdf)elixir 1.18.4
DefaultLatest stable

Erlang/OTP Version

SourceExample
.erlang-version27.0
.tool-versions (asdf)erlang 27.0
DefaultAuto-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:

  1. Copies config/ early (needed for dependency compilation)
  2. Compiles assets using mix assets.deploy
  3. Falls back to npm-based asset pipeline if needed
  4. Runs mix phx.digest for 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?

ConfigurationDefault 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

Stay UpdatedWith Latest Posts

Subscribe to our newsletter and never miss a new blog post, update, or special offer from the Miget team.