Trouble running container locally

Hello everyone - trying to evaluate strapi.

Locally it runs fine, running Node 18.16.0 - starting with yarn develop

When I try to run a container image, the build runs seemingly fine i.e. there are no errors that I notice.

My Dockerfile is very generic:

FROM node:18-alpine
# Installing libvips-dev for sharp Compatability
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY ./package.json ./yarn.lock ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN yarn config set network-timeout 600000 -g && yarn install
WORKDIR /opt/app
COPY ./ .
RUN yarn build
EXPOSE 1337
CMD ["yarn", "develop"]

When I run the container I get a (for me) non-descript error:

Error: knex: Required configuration option 'client' is missing.
    at new Client (/opt/node_modules/knex/lib/client.js:58:13)
    at knex (/opt/node_modules/knex/lib/knex-builder/Knex.js:16:28)
    at createConnection (/opt/node_modules/@strapi/database/lib/connection.js:55:24)
    at new Database (/opt/node_modules/@strapi/database/lib/index.js:34:23)
    at Database.init (/opt/node_modules/@strapi/database/lib/index.js:123:14)
    at Strapi.bootstrap (/opt/node_modules/@strapi/strapi/lib/Strapi.js:420:30)
    at Strapi.load (/opt/node_modules/@strapi/strapi/lib/Strapi.js:491:16)
    at async workerProcess (/opt/node_modules/@strapi/strapi/lib/commands/actions/develop/action.js:110:26)

When I run with a node:16 base image the error changes to

Error: knex: Required configuration option 'client' is missing.
    at new Client (/opt/node_modules/knex/lib/client.js:58:13)
    at knex (/opt/node_modules/knex/lib/knex-builder/Knex.js:16:28)
    at createConnection (/opt/node_modules/@strapi/database/lib/connection.js:55:24)
    at new Database (/opt/node_modules/@strapi/database/lib/index.js:34:23)
    at Function.Database.init (/opt/node_modules/@strapi/database/lib/index.js:123:14)
    at Strapi.bootstrap (/opt/node_modules/@strapi/strapi/lib/Strapi.js:420:30)
    at Strapi.load (/opt/node_modules/@strapi/strapi/lib/Strapi.js:491:16)
    at async workerProcess (/opt/node_modules/@strapi/strapi/lib/commands/actions/develop/action.js:110:26)

Any ideas what I am doing wrong?

1 Like

The same problem. Created project successfully at one PC. Then get it from git at another PC. After ‘npm install’ trying to start the App… but it shows the same error:
“knex: Required configuration option ‘client’ is missing”
exactly as in your example

Well, I was being a little silly, tired, whatever.
I made the assumption that the .env file in my local directory was somehow magically applied when running docker run...
So, as I am still evaluating I explicitly set all env’s in my Dockerfile and it works just fine.

FROM node:16-alpine
# Installing libvips-dev for sharp Compatability
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}

ENV HOST=0.0.0.0
ENV PORT=1337
ENV APP_KEYS=***
ENV API_TOKEN_SALT=***
ENV ADMIN_JWT_SECRET=***
ENV TRANSFER_TOKEN_SALT=***
# Database
ENV DATABASE_CLIENT=postgres
ENV DATABASE_HOST=localhost
ENV DATABASE_PORT=5432
ENV DATABASE_NAME=foobar
ENV DATABASE_USERNAME=strapiadmin
ENV DATABASE_PASSWORD=*****
ENV DATABASE_SSL=false
ENV JWT_SECRET=*****

WORKDIR /opt/
COPY ./package.json ./yarn.lock ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN yarn config set network-timeout 600000 -g && yarn install
WORKDIR /opt/app
COPY ./ .
RUN yarn build
EXPOSE 1337
RUN env
CMD ["yarn", "develop"]

If you are are using sqlite, then it may be because it isn’t finding a suitable sqlite package to use.

There is special logic in @strapi/database/lib/connection.js to deal with sqlite:

const getSqlitePackageName = () => {
  // NOTE: allow forcing the package to use (mostly used for testing purposes)
  if (typeof process.env.SQLITE_PKG !== 'undefined') {
    return process.env.SQLITE_PKG;
  }

  // NOTE: this tries to find the best sqlite module possible to use
  // while keeping retro compatibility
  return (
    trySqlitePackage('better-sqlite3') ||
    trySqlitePackage('@vscode/sqlite3') ||
    trySqlitePackage('sqlite3')
  );
};

You can use either one of the three ‘known’ packages or specify another one via SQLITE_PKG.