C++ on Miren
C++ isn't auto-detected, so you deploy it with a Dockerfile.miren that compiles your
program and runs the binary. This guide uses the header-only
cpp-httplib library.
Ask your AI coding agent to "set up this C++ 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 C++, 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 listen on 0.0.0.0:
#include "httplib.h"
#include <cstdlib>
int main() {
httplib::Server svr;
svr.Get("/", [](const httplib::Request &, httplib::Response &res) {
res.set_content("Hello from C++ on Miren!\n", "text/plain");
});
const char *p = std::getenv("PORT");
int port = p ? std::atoi(p) : 8080;
if (!svr.listen("0.0.0.0", port)) {
return 1; // bind/startup failed — surface it to the deploy
}
return 0;
}
The Dockerfile
Create Dockerfile.miren in your project root. It fetches the single httplib.h header
and compiles with pthreads:
FROM gcc:14 AS build
WORKDIR /app
RUN apt-get update -y && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
COPY main.cpp .
RUN curl -sSL -o httplib.h https://raw.githubusercontent.com/yhirose/cpp-httplib/v0.18.3/httplib.h \
&& g++ -O2 -std=c++17 -pthread -o app main.cpp
FROM debian:trixie-slim
COPY --from=build /app/app /usr/local/bin/app
EXPOSE 8080
CMD ["app"]
The gcc:14 image is built on Debian trixie (glibc 2.38, a newer libstdc++). Running
the binary on an older base like debian:12-slim fails at startup with
GLIBC_2.38 not found / GLIBCXX_3.4.32 not found. Use a runtime base from the same
or newer Debian release (debian:trixie-slim), or statically link the C++ runtime
with -static-libstdc++ -static-libgcc.
.dockerignore
.git
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: /usr/local/bin/app
Then create .miren/app.toml naming your app and deploy from your project root:
name = "cpp-bench"
miren deploy
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 std::getenv("KEY"):
miren env set -e LOG_LEVEL=info
miren env set -s DATABASE_URL
See App Configuration — Environment Variables.
Agent quick reference
- Detection: none — requires
Dockerfile.miren - Build: fetch
httplib.h;g++ -O2 -std=c++17 -pthread -o app main.cppongcc:14 - Runtime glibc/libstdc++: use
debian:trixie-slim(matchesgcc:14) — older bases crash onGLIBC_2.38/GLIBCXX_3.4.32 - Service is required: define a
Procfile(web: /usr/local/bin/app) — the imageCMDis not used - Port:
std::getenv("PORT");svr.listen("0.0.0.0", port) - Env vars:
miren env set -e/-s; read withstd::getenv
Next steps
- C on Miren — the C sibling guide
- Using Dockerfile.miren — how custom builds work
- Deployment — how deploys build and activate