Files
floci/Dockerfile.native-package
T
Conor Heine 43e9ca18a0 fix(docker): make bind-mounted /var/run/docker.sock work on all hosts (#602)
The published images run as USER 1001 with primary group root. On Docker
Desktop (macOS/Windows) /var/run/docker.sock is owned root:root inside
containers so the floci process can open it via the group-0 bit, but on
native Linux Docker (and Rootless/Podman) the socket is owned by
root:<docker-group> with mode 660 — and the floci user is not a member
of that group. This silently breaks ECR, Lambda, and RDS service
emulation on those hosts: floci's docker-java client gets BindException
/ SocketException and reports CREATE_FAILED on AWS::ECR::Repository.

Fix: ship a docker/entrypoint.sh modeled on the docker-library/postgres
pattern. It starts as root, stats the bind-mounted socket to learn the
host's docker GID, ensures a group with that GID exists, adds the floci
user to it, then `exec gosu floci` re-execs the same script as uid 1001
with the supplementary group set. The 'if id -u == 0' guard means
downstream `user:` overrides in compose files keep working unchanged.

Verified end-to-end on native Linux (Pop!_OS, docker GID 999) using a
minimal CDK bootstrap repro: AWS::ECR::Repository goes from CREATE_FAILED
to CREATE_COMPLETE and the registry:2 sidecar comes up cleanly. pid 1
runs as Uid:1001 Gid:0 Groups:999.

Implementation notes:
- All three Dockerfiles keep their original base images
  (quarkus-micro-image, ubi9-minimal, eclipse-temurin alpine).
- Dockerfile.native gains a tools builder stage that uses the canonical
  Red Hat pattern (`dnf install --installroot`) to install shadow-utils
  into a stagable /toolsroot, which the runtime stage wholesale-copies
  into quarkus-micro-image. Image growth: ~42 MB (quarkus-micro has no
  package manager and lacks groupadd/usermod by itself).
- Dockerfile.native-package adds shadow-utils via microdnf (already had
  the package manager).
- Dockerfile.jvm-package adds shadow + ca-certificates via apk so the
  entrypoint can use the same useradd/groupadd/usermod syntax across
  all three image variants.
- gosu 1.17 is downloaded and SHA256-pinned (rather than GPG-verified
  as Postgres does) to avoid pulling gnupg2 into the runtime layers
  and to sidestep a gpgme dependency conflict in ubi9-minimal.
2026-04-25 14:09:11 -05:00

50 lines
1.7 KiB
Docker

FROM registry.access.redhat.com/ubi9-minimal:9.7
ARG VERSION=latest
# Automatically set by Docker BuildKit to "amd64" or "arm64"
ARG TARGETARCH
ENV FLOCI_VERSION=${VERSION}
ENV FLOCI_STORAGE_PERSISTENT_PATH=/app/data
ENV GOSU_VERSION=1.17
ENV GOSU_AMD64_SHA256=bbc4136d03ab138b1ad66fa4fc051bafc6cc7ffae632b069a53657279a450de3
ENV GOSU_ARM64_SHA256=c3805a85d17f4454c23d7059bcb97e1ec1af272b90126e79ed002342de08389b
RUN set -eux; \
microdnf install -y --nodocs shadow-utils; \
microdnf clean all; \
useradd -r -u 1001 -g root -d /app -s /sbin/nologin floci; \
arch="$(uname -m)"; \
case "$arch" in \
x86_64) gosuArch='amd64'; gosuSha256="$GOSU_AMD64_SHA256" ;; \
aarch64) gosuArch='arm64'; gosuSha256="$GOSU_ARM64_SHA256" ;; \
*) echo >&2 "unsupported arch: $arch"; exit 1 ;; \
esac; \
curl -fsSL -o /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-${gosuArch}"; \
echo "${gosuSha256} /usr/local/bin/gosu" | sha256sum -c -; \
chmod +x /usr/local/bin/gosu; \
gosu --version; \
gosu nobody true
WORKDIR /app
RUN mkdir -p /app/data \
&& chown -R 1001:root /app \
&& chmod -R g+rwX /app
VOLUME /app/data
COPY --chown=1001:root native/${TARGETARCH}/ /app/
RUN mv /app/*-runner /app/application && chmod +x /app/application
COPY docker/entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
EXPOSE 4566
HEALTHCHECK --interval=5s --timeout=3s --retries=5 \
CMD curl -f http://localhost:4566/_floci/health || exit 1
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["/app/application", "-Dquarkus.http.host=0.0.0.0"]