Skip to content

Commit 2f8d840

Browse files
committed
fix: use runtime user: directive instead of build-arg UID/GID
Build args require rebuilding the image to change UID/GID and don't work with pre-built images from GHCR. Switch to compose user: directive which overrides at runtime via PUID/PGID environment variables. This works with both local builds and pulled images. https://claude.ai/code/session_0153nX7vQSjEFPpZTgZdDmu5
1 parent 0368126 commit 2f8d840

2 files changed

Lines changed: 4 additions & 11 deletions

File tree

Dockerfile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ FROM alpine:3.20
4646
RUN apk add --no-cache ca-certificates tzdata
4747

4848
# Create non-root user for runtime security.
49-
# PUID/PGID let you match the host directory owner when using bind mounts.
50-
# Build with: docker build --build-arg PUID=$(id -u) --build-arg PGID=$(id -g) .
51-
ARG PUID=1000
52-
ARG PGID=1000
53-
RUN addgroup -g "$PGID" chronicle \
54-
&& adduser -D -H -s /sbin/nologin -G chronicle -u "$PUID" chronicle
49+
RUN adduser -D -H -s /sbin/nologin chronicle
5550

5651
# Copy the compiled binary.
5752
COPY --from=builder /chronicle /usr/local/bin/chronicle

docker-compose.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ services:
1919
build:
2020
context: .
2121
dockerfile: Dockerfile
22-
args:
23-
# Match container UID/GID to the host user that owns the bind-mount
24-
# directory. Override in .env or shell: PUID=$(id -u) PGID=$(id -g)
25-
PUID: ${PUID:-1000}
26-
PGID: ${PGID:-1000}
2722
container_name: chronicle
23+
# Match the host directory owner for bind-mount permissions.
24+
# Set PUID/PGID as environment variables (default: 1000).
25+
user: "${PUID:-1000}:${PGID:-1000}"
2826
ports:
2927
- "8080:8080"
3028
restart: unless-stopped

0 commit comments

Comments
 (0)