Skip to content

Commit 4a2cfae

Browse files
committed
Add PUID/PGID
1 parent 3f52b52 commit 4a2cfae

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

Dockerfile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,38 @@ FROM alpine:3
4848

4949
WORKDIR /app
5050

51-
# Install runtime dependencies
51+
# Install runtime dependencies including su-exec for user switching
5252
RUN apk add --no-cache \
5353
ca-certificates \
5454
wget \
5555
ffmpeg \
56-
libheif
56+
libheif \
57+
su-exec
5758

5859
# Copy backend binary
5960
COPY --from=backend-builder /app/sbv .
6061

6162
# Copy frontend build
6263
COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
6364

65+
# Copy entrypoint script
66+
COPY docker-entrypoint.sh /usr/local/bin/
67+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
68+
6469
# Create data directory for database
6570
RUN mkdir -p /data
6671

6772
# Set environment variables
68-
ENV PORT=8081
69-
ENV DB_PATH_PREFIX=/data
73+
ENV PORT=8081 \
74+
DB_PATH_PREFIX=/data \
75+
PUID=1000 \
76+
PGID=1000
7077

7178
# Expose port
7279
EXPOSE 8081
7380

81+
# Use entrypoint to handle user switching
82+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
83+
7484
# Run the application
7585
CMD ["./sbv"]

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Run the latest stable version:
1313
docker run -d \
1414
-p 8081:8081 \
1515
-v $(pwd)/data:/data \
16+
-e PUID=1000 \
17+
-e PGID=1000 \
1618
ghcr.io/lowcarbdev/sbv:stable
1719
```
1820

@@ -26,6 +28,9 @@ services:
2628
- "8081:8081"
2729
volumes:
2830
- ./data:/data
31+
environment:
32+
- PUID=1000
33+
- PGID=1000
2934
restart: unless-stopped
3035
```
3136
@@ -47,6 +52,13 @@ services:
4752
- **Frontend**: React with Vite and Bootstrap CSS
4853
- **Database**: SQLite (stores messages, including media as BLOBs)
4954
55+
## Environment Variables
56+
57+
- `PUID` - User ID to run the application as (default: `1000`)
58+
- `PGID` - Group ID to run the application as (default: `1000`)
59+
60+
**Note on PUID/PGID**: Setting these to match your host user ensures that files created in the mounted volume have the desired permissions. Find your UID/GID with `id -u` and `id -g`.
61+
5062
## Data Persistence
5163

5264
The Docker setup uses a bind mount to persist the database:

compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ services:
1313
environment:
1414
- PORT=8081
1515
- DB_PATH_PREFIX=/data
16+
- PUID=1000
17+
- PGID=1000
1618
restart: unless-stopped
1719
healthcheck:
1820
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:8081/api/health"]

docker-entrypoint.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Default UID and GID if not specified
5+
PUID="${PUID:-1000}"
6+
PGID="${PGID:-1000}"
7+
8+
# Create group if it doesn't exist
9+
if ! getent group sbv >/dev/null 2>&1; then
10+
addgroup -g "${PGID}" sbv
11+
fi
12+
13+
# Create user if it doesn't exist
14+
if ! getent passwd sbv >/dev/null 2>&1; then
15+
adduser -D -u "${PUID}" -G sbv sbv
16+
fi
17+
18+
# Ensure the user has the correct UID/GID
19+
if [ "$(id -u sbv)" != "${PUID}" ] || [ "$(id -g sbv)" != "${PGID}" ]; then
20+
deluser sbv >/dev/null 2>&1 || true
21+
delgroup sbv >/dev/null 2>&1 || true
22+
addgroup -g "${PGID}" sbv
23+
adduser -D -u "${PUID}" -G sbv sbv
24+
fi
25+
26+
# Ensure data directory exists and has correct permissions
27+
mkdir -p "${DB_PATH_PREFIX:-/data}"
28+
chown -R sbv:sbv "${DB_PATH_PREFIX:-/data}"
29+
30+
# Log the user we're running as
31+
echo "Running as UID=${PUID} GID=${PGID}"
32+
33+
# Switch to the sbv user and execute the application
34+
exec su-exec sbv "$@"

0 commit comments

Comments
 (0)