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 usingbackstage 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.- Install dependencies
- Use Yarn v3+ (Backstage uses Yarn Berry). Install in immutable mode so the lockfile is enforced:
- Generate TypeScript types
- Compile or type-check to ensure any generated types are available:
- Build the backend bundle
- Produce the
bundle.tar.gzandskeleton.tar.gzartifacts underpackages/backend/dist.
packages/backend/dist/bundle.tar.gzpackages/backend/dist/skeleton.tar.gz
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.Build the Docker image
From the repository root (so thepackages/backend/dist artifacts are in context), run:
-f packages/backend/Dockerfilespecifies the Dockerfile path.- The final
.is the build context (typically the repo root). DOCKER_BUILDKIT=1enables BuildKit features.
Run the container locally
By default the Backstage backend listens on port 7000. Run the container and map the port: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 thedistartifacts. - 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/distso the Dockerfile COPY steps succeed.
Links and references
- Backstage documentation: https://backstage.io/docs
- Docker BuildKit: https://docs.docker.com/develop/develop-images/build_enhancements/
- Yarn v3 (Berry): https://yarnpkg.com/getting-started
- Kubernetes: https://kubernetes.io/docs/
- Amazon ECS: https://aws.amazon.com/ecs/