vocascan-server
vocascan-server copied to clipboard
Container crashes when using sqlite as DB dialect
Describe the bug Docker container crashes on startup when current Dockerfile is used for the build or the official image, and one selects sqlite as DB backend.
To Reproduce Steps to reproduce the behavior: Via Dockerfile
- Clone repository
- Build docker container using docker build
- Change DB backend to sqlite
- Use official traefik installation way to start the container
- Container won't start, the docs will produce the below stacktrace
Via official container
- Use official traefik installation way to start the container
- Change DB backend to sqlite
- Container won't start, the docs will produce the below stacktrace
Expected behavior Container should start without any problems.
Desktop (please complete the following information):
- OS: Docker version 20.10.21, build baeda1f
- node version: node-14.21.2
- npm version: 6.14.17
- database dialect: sqlite
- commit ref: ae77ac3
Additional context Traceback
info: loaded config file "/etc/vocascan/vocascan.config.js"
error: unhandledRejection: Please install sqlite3 package manually
Error: Please install sqlite3 package manually
at ConnectionManager._loadDialectModule (/app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:81:15)
at new ConnectionManager (/app/node_modules/sequelize/lib/dialects/sqlite/connection-manager.js:24:21)
at new SqliteDialect (/app/node_modules/sequelize/lib/dialects/sqlite/index.js:15:30)
at new Sequelize (/app/node_modules/sequelize/lib/sequelize.js:340:20)
at Object.db.init (/app/database/index.js:34:20)
at createServer (/app/server.js:22:12)
at Command.<anonymous> (/app/cmd/web.js:18:26)
at Command.listener [as _actionHandler] (/app/node_modules/commander/lib/command.js:488:17)
at /app/node_modules/commander/lib/command.js:1227:65
Possible solution: I changed the Dockerfile to the following, and at least the error disappeared. Need to test further whether the container works as expected or not.
FROM node:14-alpine as builder
RUN apk add --no-cache build-base python3
WORKDIR /build
COPY ./package*.json ./
RUN npm i --only=production
FROM node:14-alpine
WORKDIR /app
COPY --from=builder /build/node_modules /app/node_modules
COPY . .
RUN npm link
# Added this line explicitly. Adding it in the builder context didn't work somehow.
RUN npm install sqlite3
CMD ["vocascan-server", "web"]
Hello @js-on,
this is currently a bug which has not been fixed. It definitely was working sometime before. We have a custom postinstall hook, which normally should install sqlite if the --sqlite
flag is used on npm ci --sqlite
. Normally this should also work inside of the builder stage, but it could be that some native stuff is not correctly copied.
In the meantime, however, there are two ways to fix this problem.
- Use a different database than Sqlite3, for example Postgresql. This lets you get your server up and running.
- Either your way directly modifying the docker build script file, or write a wrapper around it, as shown below: create a "Dockerfile" in your directory with the following content:
FROM vocascan/server:latest
RUN npm install sqlite3
After that update your "docker-compose.yml" file and add the "build" property and remove the "image" property. This could look like this:
version: "3.8"
services:
vocascan:
restart: always
build:
context: .
dockerfile: Dockerfile
tty: true
environment:
VOCASCAN_CONFIG: "/etc/vocascan/vocascan.config.js"
ports:
- "8000:8000"
volumes:
- "./vocascan.config.js:/etc/vocascan/vocascan.config.js:ro"
This will pull the vocascan/server image as base image, and will build a local image with the sqlite3 npm package installed. I just tested it locally, with success.