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.
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.
Does this source build 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.
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"]
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
Deploy
The Dockerfile's CMD starts the app. Miren uses it as the web service's startup default,
so you don't need a Procfile or service command.
Create .miren/app.toml naming your app and deploy from your project root:
name = "dart-bench"
miren deploy
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/serverondart:stable - Runtime:
debian:12-slim(glibc) — the compiled exe won't run onscratch - Startup: inherited from the Dockerfile
CMD; noProcfileor service command needed - Port:
Platform.environment['PORT']; bind0.0.0.0viashelf_io.serve - Env vars:
miren env set -e/-s; read withPlatform.environment
Next steps
- Using Dockerfile.miren — how custom builds work
- App Configuration — customize
.miren/app.toml - Deployment — how deploys build and activate