Fix database not initializing in Docker (no db file created)
Root cause: DATABASE_URL used a relative path (file:./data/rackmapper.db).
Prisma CLI (migrate deploy) resolves relative SQLite paths from the
prisma/ schema directory -> /app/prisma/data/rackmapper.db, while the
Prisma Client at runtime resolves from CWD -> /app/data/rackmapper.db.
The migration ran against a different path than the bind mount, so no
database file ever appeared in /app/data (the mounted volume).
Fixes:
- Change DATABASE_URL to absolute path: file:/app/data/rackmapper.db
everywhere (docker-compose, .env.example, UNRAID.md)
- Replace inline CMD with docker-entrypoint.sh:
mkdir -p /app/data before migrating (safety net)
npx prisma migrate deploy with set -e so failures are visible
exec node dist/server/index.js
This surfaces migration errors in docker logs instead of silently
exiting, and ensures the data dir always exists before SQLite opens it
- Update .env.example to reflect plain ADMIN_PASSWORD and COOKIE_SECURE
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
10
.env.example
10
.env.example
@@ -3,14 +3,18 @@
|
|||||||
|
|
||||||
# Admin credentials
|
# Admin credentials
|
||||||
ADMIN_USERNAME=admin
|
ADMIN_USERNAME=admin
|
||||||
ADMIN_PASSWORD_HASH= # Generate with: npx ts-node scripts/hashPassword.ts yourpassword
|
ADMIN_PASSWORD= # Plain-text password
|
||||||
|
|
||||||
# JWT
|
# JWT
|
||||||
JWT_SECRET= # Min 32 random chars — generate with: openssl rand -hex 32
|
JWT_SECRET= # Min 32 random chars — generate with: openssl rand -hex 32
|
||||||
JWT_EXPIRY=8h
|
JWT_EXPIRY=8h
|
||||||
|
|
||||||
# Database (relative path inside container; bind-mounted to ./data/)
|
# Cookie security — set to true only if behind an HTTPS reverse proxy
|
||||||
DATABASE_URL=file:./data/rackmapper.db
|
COOKIE_SECURE=false
|
||||||
|
|
||||||
|
# Database — absolute path avoids Prisma CLI vs runtime resolution mismatch
|
||||||
|
# In Docker this maps to the bind-mounted /app/data volume
|
||||||
|
DATABASE_URL=file:/app/data/rackmapper.db
|
||||||
|
|
||||||
# Server
|
# Server
|
||||||
PORT=3001
|
PORT=3001
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ RUN npm run build
|
|||||||
# Ensure data directory exists for SQLite bind mount
|
# Ensure data directory exists for SQLite bind mount
|
||||||
RUN mkdir -p /app/data
|
RUN mkdir -p /app/data
|
||||||
|
|
||||||
|
# Copy and make entrypoint executable
|
||||||
|
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
|
||||||
|
RUN chmod +x /app/docker-entrypoint.sh
|
||||||
|
|
||||||
EXPOSE 3001
|
EXPOSE 3001
|
||||||
|
|
||||||
# Apply pending migrations then start
|
ENTRYPOINT ["/app/docker-entrypoint.sh"]
|
||||||
CMD ["sh", "-c", "npx prisma migrate deploy && node dist/server/index.js"]
|
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ Click **Add another Path, Port, Variable, Label or Device** → select **Variabl
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| Node Environment | `NODE_ENV` | `production` |
|
| Node Environment | `NODE_ENV` | `production` |
|
||||||
| Port | `PORT` | `3001` |
|
| Port | `PORT` | `3001` |
|
||||||
| Database URL | `DATABASE_URL` | `file:./data/rackmapper.db` |
|
| Database URL | `DATABASE_URL` | `file:/app/data/rackmapper.db` |
|
||||||
| Admin Username | `ADMIN_USERNAME` | `admin` *(or your preferred username)* |
|
| Admin Username | `ADMIN_USERNAME` | `admin` *(or your preferred username)* |
|
||||||
| Admin Password | `ADMIN_PASSWORD` | `yourpassword` |
|
| Admin Password | `ADMIN_PASSWORD` | `yourpassword` |
|
||||||
| JWT Secret | `JWT_SECRET` | `a-long-random-string-min-32-chars` |
|
| JWT Secret | `JWT_SECRET` | `a-long-random-string-min-32-chars` |
|
||||||
@@ -151,7 +151,7 @@ docker run -d \
|
|||||||
-v /mnt/user/appdata/rackmapper/data:/app/data \
|
-v /mnt/user/appdata/rackmapper/data:/app/data \
|
||||||
-e NODE_ENV=production \
|
-e NODE_ENV=production \
|
||||||
-e PORT=3001 \
|
-e PORT=3001 \
|
||||||
-e DATABASE_URL="file:./data/rackmapper.db" \
|
-e DATABASE_URL="file:/app/data/rackmapper.db" \
|
||||||
-e ADMIN_USERNAME=admin \
|
-e ADMIN_USERNAME=admin \
|
||||||
-e ADMIN_PASSWORD=yourpassword \
|
-e ADMIN_PASSWORD=yourpassword \
|
||||||
-e JWT_SECRET=a-long-random-string-min-32-chars \
|
-e JWT_SECRET=a-long-random-string-min-32-chars \
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- NODE_ENV=production
|
- NODE_ENV=production
|
||||||
- PORT=3001
|
- PORT=3001
|
||||||
- DATABASE_URL=file:./data/rackmapper.db
|
- DATABASE_URL=file:/app/data/rackmapper.db
|
||||||
- ADMIN_USERNAME=${ADMIN_USERNAME:-admin}
|
- ADMIN_USERNAME=${ADMIN_USERNAME:-admin}
|
||||||
- ADMIN_PASSWORD=${ADMIN_PASSWORD}
|
- ADMIN_PASSWORD=${ADMIN_PASSWORD}
|
||||||
- JWT_SECRET=${JWT_SECRET}
|
- JWT_SECRET=${JWT_SECRET}
|
||||||
|
|||||||
17
docker-entrypoint.sh
Normal file
17
docker-entrypoint.sh
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "[entrypoint] RackMapper starting..."
|
||||||
|
|
||||||
|
# Ensure the data directory exists and is writable
|
||||||
|
mkdir -p /app/data
|
||||||
|
echo "[entrypoint] Data directory: $(ls -la /app/data)"
|
||||||
|
|
||||||
|
# Run migrations (creates the SQLite file if it doesn't exist)
|
||||||
|
echo "[entrypoint] Running database migrations..."
|
||||||
|
npx prisma migrate deploy
|
||||||
|
echo "[entrypoint] Migrations complete."
|
||||||
|
|
||||||
|
# Start the server
|
||||||
|
echo "[entrypoint] Starting server..."
|
||||||
|
exec node dist/server/index.js
|
||||||
Reference in New Issue
Block a user