Skip to main content

Dart on Miren

Dart isn't auto-detected, so you deploy it with a Dockerfile.miren that compiles a native executable and runs it on a minimal image. This guide uses the shelf server stack.

Let your agent do this

Ask your AI coding agent to "set up this Dart app on Miren" after installing the Miren agent skills. It adds the Dockerfile.miren, confirms the server binds 0.0.0.0:$PORT, and deploys — using this page as its reference.

Do you need a Dockerfile?

Yes. Miren doesn't auto-detect Dart, so add a Dockerfile.miren to your project root. Miren builds from it instead of guessing the stack — see Using Dockerfile.miren.

Want native support?

Miren auto-detects and builds common stacks (Python, Node, Bun, Go, Ruby, Rust) without a Dockerfile. This language isn't one of them yet — if you'd like first-class support, request it.

Bind to the injected port

Miren injects PORT and routes traffic to it, so read PORT and bind 0.0.0.0:

import 'dart:io';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;

void main() async {
final port = int.parse(Platform.environment['PORT'] ?? '8080');
handler(Request req) => Response.ok('Hello from Dart on Miren!\n');
await shelf_io.serve(handler, '0.0.0.0', port);
print('listening on 0.0.0.0:$port');
}

The Dockerfile

Create Dockerfile.miren in your project root. dart compile exe produces a native binary:

# ----- Build stage -----
FROM dart:stable AS builder
WORKDIR /app
COPY pubspec.* ./
RUN dart pub get
COPY . .
RUN dart pub get --offline && dart compile exe bin/server.dart -o /app/server

# ----- Runtime stage (glibc for the compiled exe) -----
FROM debian:12-slim
RUN apt-get update -y && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/server /app/server
EXPOSE 8080
CMD ["/app/server"]
Run the compiled exe on glibc, not scratch

dart compile exe produces a dynamically-linked binary that needs a C library at runtime. Running it on scratch fails to boot; use a small glibc image like debian:12-slim. (Copying Dart's /runtime/ directory is only needed for AOT snapshots run with dartaotruntime, not for compile exe.)

.dockerignore

.git
.dart_tool

Set up the app

Even with a Dockerfile.miren, Miren needs at least one service defined — it doesn't use the image's CMD as the start command. Add a Procfile:

web: /app/server

Then create .miren/app.toml naming your app and deploy from your project root:

name = "dart-bench"
miren deploy
Deploying without a service fails

If no service is defined, the build succeeds but the deploy stops with no services defined: please define at least one service in a Procfile or .miren/app.toml.

Environment variables

Set variables with miren env set-e for plain values, -s for secrets (masked in output and logs). Read them with Platform.environment['KEY']:

miren env set -e LOG_LEVEL=info
miren env set -s DATABASE_URL

You can also declare variables in .miren/app.toml:

[[env]]
key = "DATABASE_URL"
value = ""
required = true
sensitive = true

See App Configuration — Environment Variables.

Agent quick reference

  • Detection: none — requires Dockerfile.miren (compiled exe)
  • Build: dart compile exe bin/server.dart -o /app/server on dart:stable
  • Runtime: debian:12-slim (glibc) — the compiled exe won't run on scratch
  • Service is required: define a Procfile (web: /app/server) — the image CMD is not used
  • Port: Platform.environment['PORT']; bind 0.0.0.0 via shelf_io.serve
  • Env vars: miren env set -e/-s; read with Platform.environment

Next steps