How to: Create Yardstick Docker Image

I created my own as I run docker on my Pi and wanted an easy way to integrate it.

Here is my docker compose section for it:

yardstick:
    build:
      context: ./yardstick-docker
    image: yardstick-local:latest
    platform: linux/arm64
    container_name: yardstick
    restart: unless-stopped
    init: true
    network_mode: host
    environment:
      - TZ=America/New_York
    volumes:
      - type: bind
        source: ./yardstick-data
        target: /var/lib/yardstick
        bind:
          # Create this folder with UID/GID 10001 before starting (see README).
          create_host_path: false
    stop_signal: SIGINT
    stop_grace_period: 30s
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"

Dockerfile:

FROM debian:trixie-slim

ARG TARGETARCH

# The vendor bundles Python in its executable. No Python or systemd needed.
RUN set -eux; \
    test "$TARGETARCH" = arm64; \
    apt-get update; \
    apt-get install -y --no-install-recommends \
        ca-certificates curl tzdata libstdc++6 zlib1g; \
    groupadd --gid 10001 yardstick; \
    useradd --uid 10001 --gid yardstick --home-dir /var/lib/yardstick \
        --create-home --shell /usr/sbin/nologin yardstick; \
    curl --fail --location --retry 3 \
        "https://yardstickhome.com/download/yardstick_${TARGETARCH}.deb" \
        --output /tmp/yardstick.deb; \
    apt-get install -y --no-install-recommends /tmp/yardstick.deb; \
    test -x /opt/yardstick/yardstick; \
    rm -f /tmp/yardstick.deb; \
    rm -rf /var/lib/apt/lists/*

ENV HOME=/var/lib/yardstick \
    XDG_DATA_HOME=/var/lib/yardstick \
    PYTHONUNBUFFERED=1

USER yardstick:yardstick
WORKDIR /var/lib/yardstick
EXPOSE 8477 8478
STOPSIGNAL SIGINT

HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \
    CMD curl --fail --silent --output /dev/null http://127.0.0.1:8477/ || exit 1

ENTRYPOINT ["/opt/yardstick/yardstick"]
CMD ["serve", "--port", "8477", "--note", "deb"]

Command to install:

sudo install -d -m 700 -o 10001 -g 10001 ./yardstick-data
docker compose up -d --build --no-deps yardstick
docker compose logs -f yardstick

Put the dockerfile inside yardstick-docker and make your compose file at the same level as the yardstick-docker directory.

Hope this helps someone.

3 Likes

I should also add this for anyone using docker.

You can’t use the automated update process so leave auto updates off and when a new version is available run this command on your docker host:

docker compose build --pull --no-cache yardstick
docker compose up -d --no-deps yardstick

We were chatting about this a couple weeks. I’d love a docker image too, but it doesn’t sound likely. Homelab / docker?

BTW - I think a helpful use case for a docker image is that it would enable it to run as an addon in Home Assistant.

Yeah, my code works flawlessly so if you already have a docker compose file that you are using to run other docker stuff, you can just drop my section in and add the dockerfile. This is building a local image from the latest version pulled from yardstick.

If they never publish an “official” docker image I’m fine with that. When I see a new version in the UI I can just SSH into my Pi and rebuild the image, it takes no time and almost zero effort.

In case anyone else is looking for an easy way to use docker or kubernetes I created a task that publishes the image (every 6 hours):

1 Like