diff --git a/Dockerfile b/Dockerfile index d781f96..207fdeb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,15 @@ -FROM --platform=$BUILDPLATFORM alpine:3 AS certs -RUN apk add --no-cache ca-certificates +ARG ALPINE_IMAGE=alpine:3.24.4@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf +FROM --platform=$BUILDPLATFORM $ALPINE_IMAGE AS certs +# Prepare the directories on the build platform so the target stage needs no emulation. +RUN apk add --no-cache ca-certificates && mkdir /runtime-work /runtime-home -FROM alpine:3 +FROM $ALPINE_IMAGE ARG TARGETPLATFORM COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=certs --chown=65534:65534 /runtime-work/ /work/ +COPY --from=certs --chown=65534:65534 /runtime-home/ /home/nobody/ COPY $TARGETPLATFORM/flagsmith /usr/local/bin/flagsmith +ENV HOME=/home/nobody WORKDIR /work +USER 65534:65534 ENTRYPOINT ["flagsmith"] diff --git a/README.md b/README.md index 6df6dc9..1ffbd0d 100644 --- a/README.md +++ b/README.md @@ -52,11 +52,16 @@ go build -o flagsmith . ## Docker ```sh -docker run --rm -v "$PWD:/work" -e FLAGSMITH_API_KEY ghcr.io/flagsmith/flagsmith-cli flag list +docker run --rm -v "$PWD:/work:ro" -e FLAGSMITH_API_KEY ghcr.io/flagsmith/flagsmith-cli flag list ``` A container has no keyring, so `flagsmith login` cannot store credentials there — pass `FLAGSMITH_API_KEY` or `FLAGSMITH_ENVIRONMENT_KEY`. +The image runs as an unprivileged user. For a command that writes to `/work`, such as `flagsmith init`, mount the directory read-write and select the user that owns it: + +- With rootful Docker and default UID mapping, add `--user "$(id -u):$(id -g)" -e HOME=/tmp` to use your host account. +- With rootless Docker and a directory owned by the daemon user, add `--user 0:0 -e HOME=/tmp`. Container UID and GID 0 map to the host account running the daemon. See [Docker's UID/GID mapping guide](https://docs.docker.com/engine/security/rootless/uid-gid-mapping/). + ## Quickstart ```sh