Failed to dockerize the project

conetxt :
i have developed a project using strapi , and now i need to make it running on a docker service:
here is dockerfile :

#Installing libvips-dev for sharp Compatibility
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 ./package-lock.json ./

ENV PATH /opt/node_modules/.bin:$PATH

RUN npm install

WORKDIR /opt/app

# Remove node_modules volume to fix SIGSEGV error

CMD ["npm", "run", "develop"]

EXPOSE 1337```


here is the docker compose file :
 ```version: "3.9"

services:
  strapi:
    container_name: strapi
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
    env_file:
      - .env
    environment:
      DATABASE_CLIENT: sqlite
      DATABASE_NAME: /app/database/db.sqlite
      NODE_ENV: development # or production
    volumes:
      - ./app:/app
      - ./database:/app/database
    ports:
      - "1337:1337" 

and here is the error i am finding

(base) walid@TechnoPhilia:~/Desktop/07-05-2023/factoorya_website/Backend$ docker compose up
[+] Running 2/2
⠿ Network backend_default Created 0.0s
⠿ Container strapi Created 0.1s
Attaching to strapi
strapi |
strapi | > backend@0.1.0 start
strapi | > strapi start
strapi |
strapi | npm ERR! path /usr/src/api
strapi | npm ERR! command failed
strapi | npm ERR! signal SIGSEGV
strapi | npm ERR! command sh -c strapi start
strapi |
strapi | npm ERR! A complete log of this run can be found in:
strapi | npm ERR! /root/.npm/_logs/2023-05-13T15_27_14_031Z-debug-0.log
strapi exited with code 1
strapi |
strapi | > backend@0.1.0 start
strapi | > strapi start
strapi |
^CGracefully stopping… (press Ctrl+C again to force)
Aborting on container exit…
[+] Running 1/1
⠿ Container strapi Stopped 0.7s
canceled

here is the complete log of the npm :

0 verbose cli /usr/local/bin/node /usr/local/bin/npm
1 info using npm@9.5.1
2 info using node@v18.16.0
3 timing npm:load:whichnode Completed in 1ms
4 timing config:load:defaults Completed in 2ms
5 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 0ms
6 timing config:load:builtin Completed in 0ms
7 timing config:load:cli Completed in 1ms
8 timing config:load:env Completed in 0ms
9 timing config:load:file:/usr/src/api/.npmrc Completed in 0ms
10 timing config:load:project Completed in 1ms
11 timing config:load:file:/root/.npmrc Completed in 1ms
12 timing config:load:user Completed in 1ms
13 timing config:load:file:/usr/local/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:setEnvs Completed in 1ms
16 timing config:load Completed in 6ms
17 timing npm:load:configload Completed in 6ms
18 timing npm:load:mkdirpcache Completed in 0ms
19 timing npm:load:mkdirplogs Completed in 0ms
20 verbose title npm start
21 verbose argv "start"
22 timing npm:load:setTitle Completed in 1ms
23 timing config:load:flatten Completed in 2ms
24 timing npm:load:display Completed in 3ms
25 verbose logfile logs-max:10 dir:/root/.npm/_logs/2023-05-13T14_53_58_254Z-
26 verbose logfile /root/.npm/_logs/2023-05-13T14_53_58_254Z-debug-0.log
27 timing npm:load:logFile Completed in 4ms
28 timing npm:load:timers Completed in 0ms
29 timing npm:load:configScope Completed in 0ms
30 timing npm:load Completed in 15ms
31 silly logfile done cleaning log files
32 timing command:run-script Completed in 803ms
33 timing command:start Completed in 805ms
34 verbose stack Error: command failed
34 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:53:27)
34 verbose stack     at ChildProcess.emit (node:events:513:28)
34 verbose stack     at maybeClose (node:internal/child_process:1091:16)
34 verbose stack     at ChildProcess._handle.onexit (node:internal/child_process:302:5)
35 verbose pkgid backend@0.1.0
36 verbose cwd /usr/src/api
37 verbose Linux 5.15.49-linuxkit
38 verbose node v18.16.0
39 verbose npm  v9.5.1
40 error path /usr/src/api
41 error command failed
42 error signal SIGTERM
43 error command sh -c strapi start
44 verbose exit 1
45 timing npm Completed in 837ms
46 verbose code 1
47 error A complete log of this run can be found in:
47 error     /root/.npm/_logs/2023-05-13T14_53_58_254Z-debug-0.log```

what id the issue here , and how to solve it ? any help ?
what id the issue here , and how to solve it ? any help ?

How does your database.js or config/env/development/database.js

There is also an automated tool I created a while ago you can use.

Though this does not use sqlite it sets it up to use MySQL or postgres in a container that you can choose. So if you ant sqlite you need to change the config once it’s setup.

I tired to use it , but the problem is , it launches the conatiner , it launches it as the first time , it does not take into consiedration the different files that i have changed along the customization of the project. , when i try to copy all the related files , and launch the docker componenet, it gives that error . do you have any suggestion , or a step by step process ? in order to use this tool to dockerize my cusotmised version of the strapi project ?
here is my databas.js file


module.exports = ({ env }) => {
  const client = env('DATABASE_CLIENT', 'sqlite');

  const connections = {
    mysql: {
      connection: {
        connectionString: env('DATABASE_URL'),
        host: env('DATABASE_HOST', 'localhost'),
        port: env.int('DATABASE_PORT', 3306),
        database: env('DATABASE_NAME', 'strapi'),
        user: env('DATABASE_USERNAME', 'strapi'),
        password: env('DATABASE_PASSWORD', 'strapi'),
        ssl: env.bool('DATABASE_SSL', false) && {
          key: env('DATABASE_SSL_KEY', undefined),
          cert: env('DATABASE_SSL_CERT', undefined),
          ca: env('DATABASE_SSL_CA', undefined),
          capath: env('DATABASE_SSL_CAPATH', undefined),
          cipher: env('DATABASE_SSL_CIPHER', undefined),
          rejectUnauthorized: env.bool(
            'DATABASE_SSL_REJECT_UNAUTHORIZED',
            true
          ),
        },
      },
      pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
    },
    mysql2: {
      connection: {
        host: env('DATABASE_HOST', 'localhost'),
        port: env.int('DATABASE_PORT', 3306),
        database: env('DATABASE_NAME', 'strapi'),
        user: env('DATABASE_USERNAME', 'strapi'),
        password: env('DATABASE_PASSWORD', 'strapi'),
        ssl: env.bool('DATABASE_SSL', false) && {
          key: env('DATABASE_SSL_KEY', undefined),
          cert: env('DATABASE_SSL_CERT', undefined),
          ca: env('DATABASE_SSL_CA', undefined),
          capath: env('DATABASE_SSL_CAPATH', undefined),
          cipher: env('DATABASE_SSL_CIPHER', undefined),
          rejectUnauthorized: env.bool(
            'DATABASE_SSL_REJECT_UNAUTHORIZED',
            true
          ),
        },
      },
      pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
    },
    postgres: {
      connection: {
        connectionString: env('DATABASE_URL'),
        host: env('DATABASE_HOST', 'localhost'),
        port: env.int('DATABASE_PORT', 5432),
        database: env('DATABASE_NAME', 'strapi'),
        user: env('DATABASE_USERNAME', 'strapi'),
        password: env('DATABASE_PASSWORD', 'strapi'),
        ssl: env.bool('DATABASE_SSL', false) && {
          key: env('DATABASE_SSL_KEY', undefined),
          cert: env('DATABASE_SSL_CERT', undefined),
          ca: env('DATABASE_SSL_CA', undefined),
          capath: env('DATABASE_SSL_CAPATH', undefined),
          cipher: env('DATABASE_SSL_CIPHER', undefined),
          rejectUnauthorized: env.bool(
            'DATABASE_SSL_REJECT_UNAUTHORIZED',
            true
          ),
        },
        schema: env('DATABASE_SCHEMA', 'public'),
      },
      pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
    },
    sqlite: {
      connection: {
        filename: path.join(
          __dirname,
          '..',
          env('DATABASE_FILENAME', 'data.db')
        ),
      },
      useNullAsDefault: true,
    },
  };

  return {
    connection: {
      client,
      ...connections[client],
      acquireConnectionTimeout: env.int('DATABASE_CONNECTION_TIMEOUT', 60000),
    },
  };
};

and here is the docker compose file :

version: "3.9"

services:
  strapi:
    container_name: strapi
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
    env_file:
      - .env
    environment:
      DATABASE_CLIENT: sqlite
      DATABASE_NAME: /app/database/db.sqlite
      NODE_ENV: development # or production
    volumes:
      - ./app:/app
      - ./database:/app/database
    ports:
      - "1337:1337"

any suggestions ?

The compose file won’t help to much you would need to share your actual Dockerfile then to see why it’s not getting copied.

It can be several reasons how are you starting the containers after you change files ?

All I tried to say is backup your own database.js, dockerfile and docker-compose then run the tool in the project and it creates a compose, and dockerfile for you then edit as needed.

You are also not bind mounting anything meaning everytime you change a file you have to REBUILD and RERUN the image.