fix: SQLite readonly error in Docker container
- Add entrypoint script that ensures /data is owned by node user before dropping privileges with su-exec - Remove USER node from Dockerfile (entrypoint handles it) - Change client depends_on to service_healthy so nginx waits for the server to pass its healthcheck before starting
This commit is contained in:
@@ -27,7 +27,7 @@ services:
|
|||||||
- inventory-network
|
- inventory-network
|
||||||
depends_on:
|
depends_on:
|
||||||
server:
|
server:
|
||||||
condition: service_started
|
condition: service_healthy
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
FROM node:18-alpine
|
FROM node:18-alpine
|
||||||
|
|
||||||
# Build tools needed for better-sqlite3 native compilation
|
# Build tools needed for better-sqlite3 native compilation
|
||||||
RUN apk add --no-cache python3 make g++
|
# su-exec for dropping privileges in entrypoint
|
||||||
|
RUN apk add --no-cache python3 make g++ su-exec
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -15,16 +16,18 @@ RUN apk del python3 make g++
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Create data directory for SQLite with proper ownership
|
# Create data directory for SQLite
|
||||||
RUN mkdir -p /data && chown node:node /data
|
RUN mkdir -p /data
|
||||||
VOLUME /data
|
VOLUME /data
|
||||||
|
|
||||||
# Run as non-root user for security
|
# Entrypoint fixes /data permissions then drops to node user
|
||||||
USER node
|
COPY docker-entrypoint.sh /usr/local/bin/
|
||||||
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 3001
|
EXPOSE 3001
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||||
CMD node -e "require('http').get('http://localhost:3001/api/health',r=>{process.exit(r.statusCode===200?0:1)}).on('error',()=>process.exit(1))"
|
CMD node -e "require('http').get('http://localhost:3001/api/health',r=>{process.exit(r.statusCode===200?0:1)}).on('error',()=>process.exit(1))"
|
||||||
|
|
||||||
|
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||||
CMD ["node", "server.js"]
|
CMD ["node", "server.js"]
|
||||||
|
|||||||
9
web/server/docker-entrypoint.sh
Executable file
9
web/server/docker-entrypoint.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Ensure data directory exists and is writable by the node user
|
||||||
|
mkdir -p /data
|
||||||
|
chown node:node /data
|
||||||
|
|
||||||
|
# Drop privileges and exec the CMD
|
||||||
|
exec su-exec node "$@"
|
||||||
Reference in New Issue
Block a user