Skip to content

Build a Forked Version of Grafana Alloy

Warning

This guide is accurate as of 2026-02-17. The build process of Grafana Alloy might change in the future. Consult the upstream Dockerfile when the build fails.

This guide will help you build a forked version of Grafana Alloy.

Steps

  1. Copy the following Dockerfile snippet and replace the FROM grafana/alloy:<VERSION> AS alloy-base line with the snippet in the Alloy Dockerfile.

    # NOTE: This dockerfile is based on https://github.com/grafana/alloy/blob/b1cb806a2d9cc53c778fe8c8ccd79d7517b95965/Dockerfile#L1
    
    FROM --platform=$BUILDPLATFORM grafana/alloy-build-image:v0.1.27 AS ui-build
    
    ARG BUILDPLATFORM
    ARG FORK_REPO=<GIT_FORKED_REPO_HERE>
    ARG FORK_BRANCH=<GIT_FORKED_BRANCH_HERE>
    
    RUN git clone ${FORK_REPO} --branch ${FORK_BRANCH} --single-branch
    RUN mkdir -p /ui
    # Copy the contents of the cloned UI directory into /ui so package.json
    # and other top-level files end up at /ui rather than /ui/ui
    RUN cp -r ./alloy/internal/web/ui/. /ui
    WORKDIR /ui
    
    RUN --mount=type=cache,target=/ui/node_modules,sharing=locked \
      npm install                                               \
      && npm run build
    
    FROM --platform=$BUILDPLATFORM grafana/alloy-build-image:v0.1.27 AS build
    
    ARG BUILDPLATFORM
    ARG FORK_REPO=<GIT_FORKED_REPO_HERE>
    ARG FORK_BRANCH=<GIT_FORKED_BRANCH_HERE>
    ARG RELEASE_BUILD=1
    
    WORKDIR /src/alloy
    
    RUN git clone ${FORK_REPO} --branch ${FORK_BRANCH} --single-branch .
    COPY --from=ui-build /ui/dist /src/alloy/internal/web/ui/dist
    
    RUN --mount=type=cache,target=/root/.cache/go-build \
      --mount=type=cache,target=/go/pkg/mod \
      GO_TAGS="netgo builtinassets promtail_journal_enabled" \
      make alloy
    
    FROM public.ecr.aws/ubuntu/ubuntu:noble AS alloy-base
    
    # Username and uid for alloy user
    ARG UID="473"
    ARG USERNAME="alloy"
    # Force non-interactive mode for tzdata package install
    ARG DEBIAN_FRONTEND="noninteractive"
    
    LABEL org.opencontainers.image.source="https://github.com/grafana/alloy"
    
    RUN apt-get update \
      && apt-get upgrade -y \
      && apt-get install -qy --no-install-recommends \
          ca-certificates \
          libsystemd0 \
          tzdata \
      && apt-get clean \
      && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
    
    
    COPY --from=build --chown=${UID}:${UID} /src/alloy/build/alloy /bin/alloy
    
    # Create alloy user in container, but do not set it as default
    #
    # NOTE: non-root support in Docker containers is an experimental,
    # undocumented feature; use at your own risk.
    RUN groupadd --gid $UID $USERNAME \
      && useradd -m -u $UID -g $UID $USERNAME \
      && mkdir -p /var/lib/alloy/data \
      && chown -R $USERNAME:$USERNAME /var/lib/alloy \
      && chmod -R 770 /var/lib/alloy
    
    ENTRYPOINT ["/bin/alloy"]
    ENV ALLOY_DEPLOY_MODE=docker
    CMD ["run", "/etc/alloy/config.alloy", "--storage.path=/var/lib/alloy/data"]
    
  2. Replace the following place in the Dockerfile with the following:

The placeholders occur two times.

  • <GIT_FORKED_REPO_HERE> with the git URL of the forked repo
  • <GIT_FORKED_BRANCH_HERE> with the branch name of the forked repo