strapi / strapi-docker

Install and run your first Strapi project using Docker
https://strapi.io
MIT License
1.16k stars 447 forks source link

Strapi container fails for docker-compose with PostgreSQL client #258

Closed nasushkov closed 3 years ago

nasushkov commented 3 years ago

Hi, I'm trying to launch Strapi in docker using the example config with PostgreSQL client. However, it fails with the following error:

strapi | Starting your app... strapi | internal/modules/cjs/loader.js:969 strapi | throw err; strapi | ^ strapi | strapi | Error: Cannot find module '../core/app-configuration' strapi | Require stack: strapi | - /srv/app/node_modules/strapi/lib/commands/develop.js strapi | - /usr/local/share/.config/yarn/global/node_modules/strapi/bin/strapi.js strapi | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15) strapi | at Function.Module._load (internal/modules/cjs/loader.js:842:27) strapi | at Module.require (internal/modules/cjs/loader.js:1026:19) strapi | at require (internal/modules/cjs/helpers.js:72:18) strapi | at Object. (/srv/app/node_modules/strapi/lib/commands/develop.js:4:27) strapi | at Module._compile (internal/modules/cjs/loader.js:1138:30) strapi | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10) strapi | at Module.load (internal/modules/cjs/loader.js:986:32) strapi | at Function.Module._load (internal/modules/cjs/loader.js:879:14) strapi | at Module.require (internal/modules/cjs/loader.js:1026:19) { strapi | code: 'MODULE_NOT_FOUND', strapi | requireStack: [ strapi | '/srv/app/node_modules/strapi/lib/commands/develop.js', strapi | '/usr/local/share/.config/yarn/global/node_modules/strapi/bin/strapi.js' strapi | ] strapi | } strapi exited with code 1

My docker version is 19.03.13

alexandrebodin commented 3 years ago

Hi @nasushkov are you launching it with a preexisting app or expecting it to create an app ?

nasushkov commented 3 years ago

Hi @alexandrebodin. I just copied the docker-compose.yml and tried to launch it on my current machine and it failed with an error above. Now, when I cloned this repo, it works well. I think this is due to the volume attached. So, if I want to add Strapi to my current docker-compose file, what should I do?

alexandrebodin commented 3 years ago

Sorry but I'm not sure I understand what you did to make it work.

You cloned the repo and ran docker-compose up in the examples folder ?

Actually you can copy the content and use it anywhere you just need to make sure the service names / depends_on option are in sync and that you don't have conflicts with volumes names :)

nasushkov commented 3 years ago

You cloned the repo and ran docker-compose up in the examples folder?

Yes, and when I just copied the yml file and ran it from a random directory in the first case it failed with an error above. So, my question was what are the prerequisites if I want to add this script to my existing docker-compose file? Do I need to copy any other data from this repo?

alexandrebodin commented 3 years ago

@nasushkov I tested it in an empty folder and it worked just fine so you should be able to use it anywhere / copy in another docker-compose no extra files required :). quite hard to debug which OS are you on ?

jancassio commented 3 years ago

I have the same Issue mentioned by @nasushkov

Running Docker for macOS:

Pulling strapi (strapi/strapi:latest)...
latest: Pulling from strapi/strapi
81fc19181915: Pull complete
ee49ee6a23d1: Pull complete
828510924538: Pull complete
a8f58c4fcca0: Pull complete
33699d7df21e: Pull complete
923705ffa8f8: Pull complete
c214b6cd5b8c: Pull complete
4c73d8285dba: Pull complete
1c58ef740d94: Pull complete
70503f89c178: Pull complete
595698e08dd3: Pull complete
f6368b395f8e: Pull complete
Digest: sha256:a179bea70ef48c156baba388be3b6a9abb54cf9b1d1176d92485c82520f87ace
Status: Downloaded newer image for strapi/strapi:latest
Creating postgres ... done
Creating strapi   ... done
Attaching to postgres, strapi
postgres  |
postgres  | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres  |
postgres  | 2020-10-15 04:11:12.379 UTC [1] LOG:  starting PostgreSQL 13.0 (Debian 13.0-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres  | 2020-10-15 04:11:12.380 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres  | 2020-10-15 04:11:12.380 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres  | 2020-10-15 04:11:12.387 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres  | 2020-10-15 04:11:12.410 UTC [26] LOG:  database system was shut down at 2020-10-15 04:06:16 UTC
postgres  | 2020-10-15 04:11:12.438 UTC [1] LOG:  database system is ready to accept connections
strapi    | Starting your app...
strapi    | Error loading the local develop command. Strapi might not be installed in your "node_modules". You may need to run "npm install"
strapi exited with code 1

My docker-compose.yml is a copy of examples folder:

version: '3'

services:
  strapi:
    container_name: strapi
    image: strapi/strapi:latest
    environment:
      - DATABASE_CLIENT=postgres
      - DATABASE_HOST=db
      - DATABASE_PORT=5432
      - DATABASE_NAME=strapi
      - DATABASE_USERNAME=strapi
      - DATABASE_PASSWORD=strapi
    ports:
      - 1337:1337
    volumes:
      - ./app:/srv/app
    depends_on:
      - db

  db:
    container_name: postgres
    image: postgres
    restart: always
    volumes:
      - ./db:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: strapi
      POSTGRES_PASSWORD: strapi
      POSTGRES_DB: strapi

Also, I tried to remove all containers, all images related to this composition and started a new one like this:

$ git clone git@github.com:strapi/strapi-docker.git
$ cd strapi-docker/examples/postgresql
$ docker-compose up
Creating network "postgresql_default" with the default driver
Pulling db (postgres:)...
latest: Pulling from library/postgres
bb79b6b2107f: Pull complete
e3dc51fa2b56: Pull complete
f213b6f96d81: Pull complete
2780ac832fde: Pull complete
ae5cee1a3f12: Pull complete
95db3c06319e: Pull complete
475ca72764d5: Pull complete
8d602872ecae: Pull complete
c4fca31f2e3d: Pull complete
a00c442835e0: Pull complete
2e2305af3390: Pull complete
6cff852bb872: Pull complete
25bb0be11543: Pull complete
4738c099c4ad: Pull complete
Digest: sha256:8f7c3c9b61d82a4a021da5d9618faf056633e089302a726d619fa467c73609e4
Status: Downloaded newer image for postgres:latest
Pulling strapi (strapi/strapi:)...
latest: Pulling from strapi/strapi
81fc19181915: Pull complete
ee49ee6a23d1: Pull complete
828510924538: Pull complete
a8f58c4fcca0: Pull complete
33699d7df21e: Pull complete
923705ffa8f8: Pull complete
c214b6cd5b8c: Pull complete
4c73d8285dba: Pull complete
1c58ef740d94: Pull complete
70503f89c178: Pull complete
595698e08dd3: Pull complete
f6368b395f8e: Pull complete
Digest: sha256:a179bea70ef48c156baba388be3b6a9abb54cf9b1d1176d92485c82520f87ace
Status: Downloaded newer image for strapi/strapi:latest
Creating postgres ... done
Creating strapi   ...

ERROR: for strapi  UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)

ERROR: for strapi  UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)
ERROR: An HTTP request took too long to complete. Retry with --verbose to obtain debug information.
If you encounter this issue regularly because of slow network conditions, consider setting COMPOSE_HTTP_TIMEOUT to a higher value (current value: 60).
nasushkov commented 3 years ago

@jancassio @alexandrebodin just stated an experiment from scratch. I created a new directory, created a new docker-compose file and copied the contents of the example. Also, I stopped all containers and removed them. Now I have the same issue as @jancassio:

ERROR: for strapi UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=120)

The related issue exists for Docker Compose. However, even the recommended read timeout (120) doesn't work for me either.

My OS is macOS Mojave 10.14.6

alexandrebodin commented 3 years ago

Hi @jancassio @nasushkov for that new error I also am getting it now... Not sure what to do as the image is practically just a node image with a startup script :/ It seems to happen to everyone lately...

@jancassio from your first logs What I'm seeing is that the .app folder that is mounted is not empty so the script thinks your have already a strapi app ready and tries to start it. Can you check that content of the .app folder ?

jancassio commented 3 years ago

@alexandrebodin

Can you check that content of the .app folder ?

Yes, seems it was created during docker-compose up. I tried to start the composition by using an empty and non empty folder.

Anyway, here's the content generated.

Screen Shot 2020-10-15 at 10 47 15
alexandrebodin commented 3 years ago

@jancassio Can you try to delete the node_modules folder and restarting ? It looks like the node_modules where not installed somehow or failed and when your retried strapi tried to start (it starts if the node_modules folder exists and is not empty) without modules so failed.

jancassio commented 3 years ago

@alexandrebodin Yes, here's the result:

$ docker-compose up                                                                                      
postgres is up-to-date
strapi is up-to-date
Attaching to postgres, strapi
strapi    | Node modules not installed. Installing...
strapi    | npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
strapi    | npm WARN deprecated boom@7.3.0: This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
strapi    | npm WARN deprecated har-validator@5.1.5: this library is no longer supported
strapi    | npm WARN deprecated @formatjs/intl-unified-numberformat@3.3.7: We have renamed the package to @formatjs/intl-numberformat
strapi    | npm WARN deprecated hoek@6.1.3: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
strapi    | npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
strapi    | npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
strapi    | npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
strapi    | npm WARN deprecated mailcomposer@3.12.0: This project is unmaintained
strapi    | npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
strapi    | npm WARN deprecated buildmail@3.10.0: This project is unmaintained
strapi    | npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
strapi    | npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
postgres  |
postgres  | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres  |
postgres  | 2020-10-15 16:12:32.741 UTC [1] LOG:  starting PostgreSQL 13.0 (Debian 13.0-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres  | 2020-10-15 16:12:32.742 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres  | 2020-10-15 16:12:32.742 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres  | 2020-10-15 16:12:32.747 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres  | 2020-10-15 16:12:32.768 UTC [26] LOG:  database system was shut down at 2020-10-15 04:21:10 UTC
postgres  | 2020-10-15 16:12:32.799 UTC [1] LOG:  database system is ready to accept connections
postgres  | 2020-10-15 16:14:33.036 UTC [34] WARNING:  could not open statistics file "pg_stat_tmp/global.stat": Operation not permitted
postgres  | 2020-10-15 16:24:33.719 UTC [30] WARNING:  could not open statistics file "pg_stat_tmp/global.stat": Operation not permitted
jancassio commented 3 years ago

@alexandrebodin @nasushkov I got something.

I removed both postgres and strapi images from docker, restarted docker, ran docker-compose pull and docker-compose up.

So restart Docker is could be the fix.

The Strapi app takes about 5 minutes to go live, so is interesting to run the stack withÏout -d flag with docker-compose command, to see the Strapi startup progress.

My Docker config (local development)

property value
CPUs 4
Memory 8GB
Swap 1GB

My docker-compose.yml (with few changes)

version: '3'

services:
  strapi:
    container_name: strapi-app
    image: strapi/strapi:latest
    environment:
      - DATABASE_CLIENT=postgres
      - DATABASE_HOST=db
      - DATABASE_PORT=5432
      - DATABASE_NAME=strapi
      - DATABASE_USERNAME=strapi
      - DATABASE_PASSWORD=strapi
    ports:
      - 1337:1337
    volumes:
      - ./app:/srv/app
    depends_on:
      - db

  db:
    container_name: strapi-db
    image: postgres
    restart: always
    volumes:
      - ./db:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: strapi
      POSTGRES_PASSWORD: strapi
      POSTGRES_DB: strapi
alexandrebodin commented 3 years ago

Hey, thanks for the update. I think I can close this issue as there is no specific bug with the image itself but more to do with latencies / docker resources.

Yeah in docker the node_modules installation is pretty slow not sure why will need to check if we can improve that somehow. Once the app is created the first time then the startup will be easier.

FYI if you are planning to deploy with docker in prod you should create a Dockerfile so your node_modules are built into the image instead ;)