> How to deploy an app in any language — Go, Java, Rust, PHP — from your own Dockerfile: when the platform picks this on its own, what the image needs and which limits apply.

<!-- https://docs.layero.ru/en/runtime/dockerfile/ -->

> **Problems with this page.** Layero fixes its documentation from
> reports. If this page was wrong, outdated, or did not have what was
> needed (even if the answer was then found in the CLI's source code), a
> short report — page, quote, problem, the command and what it returned —
> can be sent with the Layero MCP tool `report_docs_issue` or
> `POST https://api.layero.ru/public/docs-feedback`, once the user agrees.
> No sign-in, no code or data from the user's project. Template and
> rules: https://docs.layero.ru/en/agents/feedback.md

# Building from your own Dockerfile

**If the project has a `Dockerfile`, Layero can build the image from it and run it as a server app — in Go, Java, Rust, PHP or any other language.**
Dockerfile builds are in beta: support turns them on for an organization on request.

## When the platform picks this on its own

On a project's first build Layero looks at the app folder:

- **A framework or server is recognised** — Next.js, Vite, Express, FastAPI,
  Django and others — it builds as usual. A `Dockerfile` next to it changes
  nothing.
- **A ready static site** — there is an `index.html` — it is served as static
  files: faster and cheaper than an nginx container.
- **No framework recognised, but there is a `Dockerfile`** — the image is
  built from it.

A project that has already been built never changes its type by itself.

## Choosing Dockerfile by hand

- **`layero.json`** at the app root:

  ```json title="layero.json"
  { "runtime": "docker" }
  ```

- **CLI**, once: `npx layero@latest deploy -t docker`.
- **Dashboard** — project → “Settings” → “Build and deploy” → framework
  “Dockerfile”. The item is shown to organizations with beta access.

## What the image needs

- **Listen on `$PORT`.** The platform passes the port in `PORT` (`8080` by
  default); the app listens on `0.0.0.0:$PORT`. Another port is set in the
  project settings or with the `port` key in `layero.json`.
- **`linux/amd64`.** A build with `FROM --platform=linux/arm64` is refused
  before it starts.
- **Image up to 3 GB.** From 1 GB the build warns: a large image takes longer
  to wake up after idling. A multi-stage build and a small base image
  (`alpine`, `distroless`, `slim`) fix both.
- **Your own start command.** `CMD` and `ENTRYPOINT` come from the Dockerfile;
  no shell is needed in the image, `distroless` works.

## Project variables

- **At run time** they reach the container as ordinary environment variables.
- **At build time as `ARG` values.** A project variable with the same name as
  an `ARG` in the Dockerfile arrives there with its value:

  ```dockerfile
  ARG API_URL
  RUN echo "building for $API_URL" && npm run build
  ```

  Argument values stay in the image history (`docker history`), so do not pass
  passwords or tokens this way. Reserved names — `PATH`, `HOME`, `DOCKER_*`,
  `*_PROXY` and the like — are not passed as arguments.
- **At build time as a secret** — never ends up in the image or its history:

  ```dockerfile
  RUN --mount=type=secret,id=layero_env \
      . /run/secrets/layero_env && npm run build
  ```

  After you change variables, the next build rebuilds the layers that read
  them.

## Project preview

If the app answers the main page with text or JSON instead of HTML, the project overview, the deploy page and the project list show a card instead of a screenshot: the app type, the address, the response code and type, and the first lines of what the app returns. This is how APIs and pageless services look.

## Disk and state

Files the container writes to disk are **temporary**: they are lost on
restart, after idling and with a new deploy. Keep data in a database and files
in storage. Details — [Files and state](./stateless.md).

## Beta limits and what comes next

- **An app without an HTTP port** — a background worker, a long-polling bot —
  does not pass the start check yet: the platform waits for an answer on
  `$PORT`. Such apps arrive together with always-on containers, the next stage.
- **The container sleeps when idle** and wakes on the first request, like any
  server app. Always-on containers are the same next stage.
- **Private base images.** Access to a private registry for `FROM` is added in
  the project settings; a section on it will appear here once we finish
  testing.

## If the build failed

The deploy card shows the cause, and the build log shows the steps of your
Dockerfile and the error line. Common causes:

| Message | What to do |
|---|---|
| в папке проекта нет файла Dockerfile (no Dockerfile in the project folder) | Put the `Dockerfile` at the app root or set the app folder in the settings. |
| есть Dockerfile.prod, но собираем только по файлу с именем Dockerfile (only a file named Dockerfile is used) | Rename the file you need to `Dockerfile`. |
| в Dockerfile ошибка в строке N (error in Dockerfile line N) | Fix the instruction on that line: usually a typo. |
| COPY берёт файлы только из папки проекта (COPY takes files only from the project folder) | Files above the project folder (`COPY ../…`) are not in the build: move the file or make the common root the project folder. |
| не найден файл: его нет в папке проекта или он исключён в .dockerignore (file not found or excluded in .dockerignore) | Check the `COPY` path and `.dockerignore`. |
| не удалось скачать базовый образ (could not pull the base image) | Check the image name and tag in `FROM`. |
| приложения на Layero работают на linux/amd64 (apps run on linux/amd64) | Remove `--platform` or set `linux/amd64`. |
| образ получился больше 3 ГБ (image is larger than 3 GB) | A multi-stage build and a small base image. |
| не открыло порт за время запуска, хотя процесс работал (did not open the port in time, the process was running) | The server listens on another port or `127.0.0.1` (it needs `0.0.0.0` and the port from `$PORT`), or it starts slowly: Java, .NET and other heavy runtimes do not make it on the Free tier, the Pro tier helps. |
| не начало принимать запросы на своём порту (did not start accepting requests) | The server crashed on start (output — at the “Starting the app” stage) or listens on another port or `127.0.0.1`: it needs `0.0.0.0` and the port from `$PORT`. |
