Skip to main content
This guide shows how to package a Backstage backend into a Docker container so you can run it locally or deploy it with your preferred orchestrator (for example, Kubernetes or Amazon ECS). It walks through the generated backend Dockerfile, local preparation steps, image build and run commands, and CI/CD considerations. Key terms: Backstage Docker image, Docker BuildKit, Yarn v3 (Berry), backend bundle, CI/CD build agents.
Before building, make sure you understand where the Docker build context should be. The Dockerfile expects the backend bundle artifacts under packages/backend/dist in the build context (usually the repository root).

Where the Dockerfile lives

When you create a Backstage app using backstage create-app, a production-ready Dockerfile is generated for the backend package. Dockerfile path: packages/backend/Dockerfile Below is the generated Dockerfile (unchanged):

Prepare the repository (local or CI)

Before running a Docker build, produce the backend artifacts the Dockerfile expects. Run these steps locally or replicate them in your CI pipeline.
  1. Install dependencies
  • Use Yarn v3+ (Backstage uses Yarn Berry). Install in immutable mode so the lockfile is enforced:
  1. Generate TypeScript types
  • Compile or type-check to ensure any generated types are available:
  1. Build the backend bundle
  • Produce the bundle.tar.gz and skeleton.tar.gz artifacts under packages/backend/dist.
Option A — build the whole monorepo (recommended):
Option B — build only the backend package:
After these steps confirm:
  • packages/backend/dist/bundle.tar.gz
  • packages/backend/dist/skeleton.tar.gz
exist in your repo root (or in the CI build context).

Important: Docker BuildKit

Make sure Docker BuildKit is enabled when building this Dockerfile (see https://docs.docker.com/develop/develop-images/build_enhancements/). BuildKit is required for the --mount=type=cache and certain ownership behaviors used in the Dockerfile. You can enable it by setting DOCKER_BUILDKIT=1 in your build environment.
BuildKit is required for mount caching and for correct ownership handling that the Dockerfile relies on. In CI, enable BuildKit or use a builder (kaniko/buildah) that supports these Dockerfile features.

Build the Docker image

From the repository root (so the packages/backend/dist artifacts are in context), run:
Notes:
  • -f packages/backend/Dockerfile specifies the Dockerfile path.
  • The final . is the build context (typically the repo root).
  • DOCKER_BUILDKIT=1 enables BuildKit features.

Run the container locally

By default the Backstage backend listens on port 7000. Run the container and map the port:
If you override or provide additional configuration files at runtime, either include them in the image during build or mount them at runtime. The generated CMD expects app-config.yaml and app-config.production.yaml to be present in the container.

Quick reference table

CI/CD considerations

  • Reproduce the local preparation steps in your CI pipeline: install dependencies, run yarn tsc, and create the dist artifacts.
  • Ensure the CI runner enables Docker BuildKit or uses an alternative builder that supports the Dockerfile mount features.
  • Push the built image to your container registry and deploy through your preferred orchestrator (Kubernetes, AWS ECS, etc.).
  • For multi-stage or automated pipelines, make sure the build context (or artifacts archive) includes packages/backend/dist so the Dockerfile COPY steps succeed.
This sequence packages your Backstage backend into a production-ready Docker image, following recommended practices for reproducible builds and CI/CD.

Watch Video