Sign in
Log inSign up
Simen Daehlin

67 likes

·

46.4K reads

71 comments

DMehaffy (Strapi)
DMehaffy (Strapi)
Feb 8, 2022

strapi-connector-bookshelf

You won't need this on v4 as it no longer exists.

3
·
·1 reply
kalle
kalle
Feb 9, 2022

Yeah, I did my install without the quickflag and choose pg as db

·
Dom
Dom
Feb 7, 2022

Simen Daehlin thank you for this awesome Guide!

I got some of the same errors kalle was facing, as well as the error with the sharp dependency. For me running the container with an alpine image and adding some missing shared libraries did the trick.

What I did was replacing the FROM node:16 line with:

FROM node:16-alpine
RUN apk add --no-cache libc6-compat

Just leaving this here in case someone might need this.

Now while this did work splendidly on a fresh install of strapi v4 (again, thank you for this amazing guide!), weirdly enough, when I try to dockerize an existing strapi project (v.4.0.7) I get the error:

debug: ⛔️ Server wasn't able to start properly. strapi error: password authentication failed for user "strapi"

all the same while the postgres container throws the error:

DETAIL: Role "strapi" does not exist.

I followed the steps in the update you just published, to no avail. Oddly enough, when I look at the container the postgres db is running in, all the env variables etc. seem to be set properly and recognized by the container. Do you have any idea by any chance what strange mysteries could be happening here?

Just a quick heads-up: strapi-connector-bookshelf needs a node version >=10.16.0 <=14.x.x to run. Should one need the dependency, then changing the first line in the Dockerfile to

FROM node:14

fixes this issue.

1
·
·1 reply
Simen Daehlin
Simen Daehlin
Author
·Feb 8, 2022

Thanks for looking into it. I think that it is because there is no POSTGRES_DB that is defined. Also I think that we can use FROM node:14 or node:14-alpine. Don't recommend alpine images for development but yes indeed for production.

did a minor update on the files etc.

1
·
Bohan Zhang
Bohan Zhang
May 27, 2022

yarn.lock does not exist

  StrapiServerless docker build -t mystrapi:latest .
[+] Building 17.0s (9/14)
 => [internal] load build definition from Dockerfile                                                                                                                  0.0s
 => => transferring dockerfile: 37B                                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                                     0.0s
 => => transferring context: 34B                                                                                                                                      0.0s
 => [internal] load metadata for docker.io/library/node:16                                                                                                           16.9s
 => [internal] load build context                                                                                                                                     0.0s
 => => transferring context: 12.87kB                                                                                                                                  0.0s
 => CANCELED [ 1/10] FROM docker.io/library/node:16@sha256:32605ead9…                                           0.0s
 => => resolve docker.io/library/node:16@sha256:32605ead9…                                                      0.0s
 => => sha256:b025e782e09fa7e1cdfab96049de130c27dd8d641c5220335d5905760e62c53f 7.62kB / 7.62kB                                                                        0.0s
 => => sha256:32605ead97ed57bd39a8a7b0e919240e1a3218974dfc6965e61b54a801753131 1.21kB / 1.21kB                                                                        0.0s
 => => sha256:085b1865ac9604641514610a340c6490b4c641b7370b00a75686f5bff8971688 2.21kB / 2.21kB                                                                        0.0s
 => CACHED [ 2/10] RUN apt-get update && apt-get install libvips-dev                                                                                                  0.0s
 => CACHED [ 3/10] WORKDIR /opt/                                                                                                                                      0.0s
 => CACHED [ 4/10] COPY ./package.json ./                                                                                                                             0.0s
 => ERROR [ 5/10] COPY ./yarn.lock ./                                                                                                                                 0.0s
------
 > [ 5/10] COPY ./yarn.lock ./:
------
failed to compute cache key: "/yarn.lock" not found: not found

and after I comment this line I found your Dockerfile in line 3 forget to add -y for argee install, here is my Dockerfile

FROM node:16
# Installing libvips-dev for sharp compatability
RUN apt-get update && apt-get install -y libvips-dev
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY ./package.json ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN yarn config set network-timeout 600000 -g
RUN yarn install
WORKDIR /opt/app
COPY ./ .
RUN yarn build
EXPOSE 1337
CMD ["yarn", "develop"]
1
·
·1 reply
Simen Daehlin
Simen Daehlin
Author
·Jun 8, 2022

Going to do a update of the Docker file and Docker-compose file shortly.

1
·
Nabeel Shakeel
Nabeel Shakeel
Sep 15, 2022

Hi Simen Daehlin, Thanks for the wonderful article. It helps me a lot in setting up development environment on docker suing Strapi v4.

I was facing this error when using this Dockerfile to start starpi:

tw-backend  | yarn run v1.22.19
tw-backend  | $ strapi develop
tw-backend  | Starting the compilation for TypeScript files in /opt/app
tw-backend  | [2022-09-15 06:19:31.420] debug: ⛔️ Server wasn't able to start properly.
tw-backend  | [2022-09-15 06:19:31.423] error: Could not load js config file /opt/app/node_modules/@strapi/plugin-upload/strapi-server.js: 
tw-backend  | Something went wrong installing the "sharp" module
tw-backend  | 
tw-backend  | Cannot find module '../build/Release/sharp-linuxmusl-x64.node'

So, I solved this issue by by doing these two changes, move node_modules into opt/app and add install sharp

Adding my Dockerfile to save time for those who are facing the same issue

FROM node:16-alpine
# Installing libvips-dev for sharp Compatability
RUN apk update && apk add  build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/app
COPY ./package.json ./yarn.lock ./
# ENV PATH /opt/node_modules/.bin:$PATH
RUN yarn config set network-timeout 600000 -g && yarn install
RUN yarn add --verbose --platform=linuxmusl --arch=x64 sharp
# WORKDIR /opt/app
COPY ./ .
RUN yarn build
EXPOSE 1337
CMD ["yarn", "develop"]
1
·
·2 replies
Simen Daehlin
Simen Daehlin
Author
·Sep 15, 2022

Thanks the idea is not to move node modules into it as it gives more attack surface, but will re-test it. Did you try the npx tool I created which auto creates the files etc as needed?

1
·
Nabeel Shakeel
Nabeel Shakeel
Sep 15, 2022

Simen Daehlin Yes, I used your tool to create Dockerfile and docker-compose.

When I moved node_modules into /opt/app then it works because error is

error: Could not load js config file /opt/app/node_modules/@strapi/plugin-upload/strapi-server.js
·
Mincheol Kim
Mincheol Kim
Feb 4, 2022

Thank you for the detailed guide!

Unfortunately, it failed at the stage of creating a docker image. I'm using the m1 Silicon Mac Book. The error message is as follows.

sharp: Installation error: Use with glibc 2.28 requires manual installation of libvips >= 8.11.3

The docker node16 image can't be bullseye, before yarn install,

RUN apt-get update -y && \
apt-get upgrade -y libvips libvips-dev

Installing libvips with the above command failed with the same error message.

Is there a good way to solve it?

·
·5 replies
Simen Daehlin
Simen Daehlin
Author
·Feb 4, 2022

Mincheol Kim Depending on deployment, if you are working on mac you can always install brew yourself

brew install vips

Note that if we are using an alpine image it's also different, as it's using musl linux and not glibc etc.

1
·
Mincheol Kim
Mincheol Kim
Feb 4, 2022

Simen Daehlin Thank you for your answer. I'm a junior developer, so I don't understand it properly. To install vips with Brew means to install it locally, not in the docker container?

docker build -t mystrapi:latest .

When executed with the command above, it fails in the yarn install part. How can I modify the Dockerfile to install vips with brew?

Below is the error log of the docker build.

 => ERROR [6/9] RUN yarn install                                                                                                                                    77.3s
------
 > [6/9] RUN yarn install:
#11 0.330 yarn install v1.22.15
#11 0.383 [1/5] Validating package.json...
#11 0.385 [2/5] Resolving packages...
#11 0.634 [3/5] Fetching packages...
#11 35.11 info fsevents@2.3.2: The platform "linux" is incompatible with this module.
#11 35.11 info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation.
#11 35.12 [4/5] Linking dependencies...
#11 35.12 warning "@strapi/plugin-users-permissions > @strapi/helper-plugin@4.0.7" has unmet peer dependency "formik@^2.2.6".
#11 35.12 warning "@strapi/plugin-users-permissions > @strapi/helper-plugin@4.0.7" has unmet peer dependency "immer@9.0.6".
#11 35.12 warning "@strapi/plugin-users-permissions > @strapi/helper-plugin@4.0.7" has unmet peer dependency "qs@6.10.1".
#11 35.12 warning "@strapi/plugin-users-permissions > @strapi/helper-plugin@4.0.7" has unmet peer dependency "react-select@^4.0.2".
#11 35.12 warning "@strapi/plugin-users-permissions > react-redux@7.2.3" has unmet peer dependency "redux@^2.0.0 || ^3.0.0 || ^4.0.0-0".
#11 35.12 warning "@strapi/strapi > @strapi/admin > react-virtualized@9.22.3" has incorrect peer dependency "react@^15.3.0 || ^16.0.0-alpha".
#11 35.12 warning "@strapi/strapi > @strapi/admin > react-virtualized@9.22.3" has incorrect peer dependency "react-dom@^15.3.0 || ^16.0.0-alpha".
#11 35.12 warning "@strapi/strapi > @strapi/admin > styled-components@5.3.3" has unmet peer dependency "react-is@>= 16.8.0".
#11 35.12 warning "@strapi/strapi > @strapi/admin > webpack-dev-server > http-proxy-middleware@2.0.2" has unmet peer dependency "@types/express@^4.17.13".
#11 35.12 warning "@strapi/plugin-users-permissions > grant-koa@5.4.8" has unmet peer dependency "koa@>=2.0.0".
#11 35.15 warning Workspaces can only be enabled in private projects.
#11 43.85 [5/5] Building fresh packages...
#11 44.94 error /opt/node_modules/sharp: Command failed.
#11 44.94 Exit code: 1
#11 44.94 Command: (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
#11 44.94 Arguments: 
#11 44.94 Directory: /opt/node_modules/sharp
#11 44.94 Output:
#11 44.94 sharp: Installation error: Use with glibc 2.28 requires manual installation of libvips >= 8.11.3
#11 44.94 sharp: Please see sharp.pixelplumbing.com/install for required dependencies
#11 44.94 info Visit yarnpkg.com/en/docs/cli/install for documentation about this command.
------
executor failed running [/bin/sh -c yarn install]: exit code: 1
·
Simen Daehlin
Simen Daehlin
Author
·Feb 5, 2022

Mincheol Kim

So it's two things here. Sharp gets compiled, and uses this in the container so installing sharp on your mac should allow the container to build it.

If you need it inside the container, you can add

RUN apt-get update && apt-get install libvips libvips-dev -y

This is the line after from node... What you wrote in previous does an upgrade and update not installing the package.

·
Mincheol Kim
Mincheol Kim
Feb 7, 2022

Simen Daehlin

Unfortunately, the same error occurred when installed in my m1 MacBook, and the same problem continued when installed in the container.

I solved it by entering the command

platform: linux/amd64

in the docker-compose.yml file.

Thank you for the great guide!

·
Camil Blanchet
Camil Blanchet
Feb 9, 2022

Mincheol Kim

Experiencing same issue but in Development Docker image build - did you find a work-around for that?

·
kalle
kalle
Feb 5, 2022

Hi Simen,

Thanks for your demo. I hade to change

docker-compose up -d postgresdb && yarn develop

to

docker-compose up -d strapi && yarn develop

as the .env as strapi as I get that

no such service: postgresdb

But my the error I am getting when running with

docker-compose up -d strapi && yarn develop

is the following:

debug: ⛔️ Server wasn't able to start properly. error: The server does not support SSL connections

Have you run into this issue? I am on Mac OS Monterey v12.2 and node v 16.3.0

The

docker-compose up -d

is working without errors

·
·14 replies
Simen Daehlin
Simen Daehlin
Author
·Feb 5, 2022

You can use docker-compose up -d to start both. PostgresDB etc needs to match the name of the service. Not had that error lastime i got it service was not running.

·
kalle
kalle
Feb 6, 2022

Simen Daehlin

I looked into the logs, one of the issues was that the log was telling that: "Error: Knex: run $ npm install pg --save Cannot find module 'pg'" I checked the package.json file, and there was no pg installed, so when I installed strapi without the quick flag the local instance is running, when using docker-compose up -d as you mentioned, but when using docker-compose up -d strapi && yarn develop the Container postgresDB starts running, Container strapi starts but shuts after the following error: debug: ⛔️ Server wasn't able to start properly. error: role "strapi" does not exist As I am really new at this, how do I make the production db open in browser, in the same way I can run the localhost:1337 strapi in browser?

·
Simen Daehlin
Simen Daehlin
Author
·Feb 6, 2022

kalle It seems I missed installing knex and pg as dependencies when using postgres so will rectify that in the guide.

I think the reason is we need to give postgres a default database. Will try to update this on my laptop today.

·
kalle
kalle
Feb 6, 2022

Simen Daehlin

Great, looking forward to your update :) And it would be great to connect postgres with a default database as you mentioned. If possible please extend your article to how to deploy this on Heroku using Herokus's Container Registry and the Use Heroku CLI

1
·
Simen Daehlin
Simen Daehlin
Author
·Feb 7, 2022

kalle I might add an extra blog entry for Herokus's Container Registry Using Heroku CLI and how to set it up there :)

1
·
kalle
kalle
Feb 8, 2022

Simen Daehlin

Thanks for the update, in your recent update, is there provision for the following, the postgres is not running on port localhost:5432, you replied with the following "I think the reason is we need to give postgres a default database. Will try to update this on my laptop today." Or have I missed something in your update?

·
Simen Daehlin
Simen Daehlin
Author
·Feb 8, 2022

kalle So to make it work.

docker-compose up -d postgresdb && yarn develop

needs to be

docker-compose up -d postgresDB && yarn develop

note capital DB unless you changed it in docker-compose.yml file to be all lowercase.

If it still fails check that it starts. bash docker logs postgresDB -f if it says it's accepting connections then you can do yarn develop

Also the setting DATABASE_HOST=localhost can be set to 0.0.0.0 to make it available on any IP it seems to be a bit weird on mac. I had the same issue running it just as a container.

·
kalle
kalle
Feb 8, 2022

Simen Daehlin Running the following command: docker-compose up -d postgresDB && yarn develop gives me the following error: debug: ⛔️ Server wasn't able to start properly. error: role "strapi" does not exist

·
Simen Daehlin
Simen Daehlin
Author
·Feb 8, 2022

kalle How does your docker-compose file look?

·
Simen Daehlin
Simen Daehlin
Author
·Feb 8, 2022
1
·
kalle
kalle
Feb 9, 2022

Simen Daehlin Thanks :)

·
kalle
kalle
Feb 9, 2022

Simen Daehlin

{ "name": "docker-strapi-ps", "private": true, "version": "0.1.0", "description": "A Strapi application", "scripts": { "develop": "strapi develop", "start": "strapi start", "build": "strapi build", "strapi": "strapi" }, "devDependencies": {}, "dependencies": { "@strapi/strapi": "4.0.7", "@strapi/plugin-users-permissions": "4.0.7", "@strapi/plugin-i18n": "4.0.7", "pg": "8.6.0" }, "author": { "name": "A Strapi developer" }, "strapi": { "uuid": "40a2ddf2-fcc4-4f67-b1e6-1360678a556f" }, "engines": { "node": ">=12.x.x <=16.x.x", "npm": ">=6.0.0" }, "license": "MIT" }

·
Simen Daehlin
Simen Daehlin
Author
·Feb 9, 2022

kalle That's your package.json not your docker-compose file 😂😊

·
kalle
kalle
Feb 10, 2022

Simen Daehlin sorry :) heres the docker-compose file:

version: "3" services: strapi: container_name: strapi build: . image: mystrapi:latest restart: unless-stopped env_file: .env environment: DATABASE_CLIENT: ${DATABASE_CLIENT} DATABASE_HOST: postgresDB DATABASE_NAME: ${DATABASE_NAME} DATABASE_USERNAME: ${DATABASE_USERNAME} DATABASE_PORT: ${DATABASE_PORT} JWT_SECRET: ${JWT_SECRET} DATABASE_PASSWORD: ${DATABASE_PASSWORD} NODE_ENV: ${NODE_ENV} links:

  - postgresDB:postgresDB
volumes:
  - ./config:/opt/app/config
  - ./src:/opt/app/src
  - ./package.json:/opt/package.json
  - ./yarn.lock:/opt/yarn.lock
  - ./.env:/opt/app/.env
ports:
  - "1337:1337"
networks:
  - strapi
depends_on:
  - postgresDB

postgresDB: image: postgres:12.0-alpine container_name: postgresDB restart: unless-stopped env_file: .env environment: POSTGRES_USER: ${DATABASE_USERNAME} POSTGRES_PASSWORD: ${DATABASE_PASSWORD} volumes:

  - ./data:/var/lib/postgresql/data/
ports:
  - "5432:5432"
networks:
  - strapi

networks: strapi: name: Strapi driver: bridge

·
Manuel
Manuel
Feb 9, 2022

Hi first off all thank you for this tutorial.

I guess i'm missing one last step. I did everything exactly as described in the tutorial except that i don't have an build . in the docker compose but i push an image into my own container registry before it and then use that image.

So this is my docker-compose file:

version: '3'
services:
    strapi:
      container_name: strapi
      image: ghcr.io/confidato/strapi-cms:latest
      restart: unless-stopped
      env_file: .env
      environment:
        DATABASE_CLIENT: ${DATABASE_CLIENT}
        DATABASE_HOST: postgresDB
        DATABASE_NAME: ${DATABASE_NAME}
        DATABASE_USERNAME: ${DATABASE_USERNAME}
        DATABASE_PORT: ${DATABASE_PORT}
        JWT_SECRET: ${JWT_SECRET}
        DATABASE_PASSWORD: ${DATABASE_PASSWORD}
        NODE_ENV: ${NODE_ENV}
      links:
        - postgresDB:postgresDB
      volumes:
        - ./public:/public/upload
        #- ./src:/opt/app/src ### If this line is not in the file it starts.
      ports:
        - "1337:1337"
      depends_on:
        - postgresDB

    postgresDB:
      image: postgres:12.0-alpine
      container_name: postgresDB
      restart: unless-stopped
      env_file: .env
      environment:
        POSTGRES_USER: ${DATABASE_USERNAME}
        POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
        POSTGRES_DB: ${DATABASE_NAME}
      volumes:
        - ./data:/var/lib/postgresql/data/
      ports:
        - "5432:5432"

networks:
  default:
    external:
      name: network123

If i start it without the line - ./src:/opt/app/src in volumes everthing looks good but if i use docker-compose down my data won't show up again in the admin-dashboard. I guess i have a problem with my volume mapping. If I add the line - ./src:/opt/app/src strapi has an error at startup and it says: Missing api folder. Please create one at './src/api'.

Any idea where my problem is?

·
·5 replies
Simen Daehlin
Simen Daehlin
Author
·Feb 9, 2022

I do think that if you are mapping the whole src folder you will also map node_modules. Did have some issues with that before even when making node_modules outside the parent folder.

·
Manuel
Manuel
Feb 10, 2022

Simen Daehlin My dockerfile looks exactly like yours. But mounting /opt/app/src should not affect the node_modules. When I start strapi without the mounted volume I have the folders admin, api and extensions and the index.js file under the folder /opt/app/src. So exactly as I would expect. When I insert the line with the mount in my docker-compose, it seems that the api folder is missing. Any idea how you fixed it?

·
Manuel
Manuel
Feb 10, 2022

Manuel Ok do I don't know if this solution is the right way but I got it working. So for all those who have a similar problem. I have added the following line to my Strapi service:

strapi:
      ...
      volumes:
        - strapi:/opt/app/src

And created an additional volume in my docker-compose:

volumes:
  strapi:
1
·
Simen Daehlin
Simen Daehlin
Author
·Feb 11, 2022

Manuel That is a good workaround indeed. You can mount the whole project into the container too. Creating it's separate volume will work as well. Though if files change you won't get a reflection on it in the container.

If you need a reflection, bind the folders to the same folders in the container.

strapi:
        ...
        volumes:
          - config:/opt/app/config

As though avoiding mounting node_modules. If your system is different to linux.

1
·
Simen Daehlin
Simen Daehlin
Author
·Feb 17, 2022

Sorry for a bit of late reply Manuel If you docker-compose up again I think you need to do --build again to rebuild the image would that not be worth it ?

·
Usash
Usash
Feb 16, 2022

I am new at Strapi. I want to dockerize my own strapi project which is created by --quickstart. I followed your tutorial step by step. but when I try to build Dockerfile by docker build -t mystrapi:latest . command it trying to install with a few minutes and then the error message shows

=> ERROR [ 2/10] RUN apt-get update && apt-get install libvips-dev

I'm using Docker Desktop on Windows.

1.PNG

2.PNG

·
·1 reply
Simen Daehlin
Simen Daehlin
Author
·Feb 16, 2022

You need RUN apt-get update && apt-get install libvips-dev -y note the -y to say yes to all.

1
·
Usash
Usash
Feb 18, 2022

After following all step by step my project run successfully in docker container. but I want to run strapi project locally by yarn develop command and the postgres will be run in docker container by docker-compose -d up postgresDB. The Docker is completely fine and do his job as run postgresDB alone. but when i try yarn develop i got error and crash my project 1.PNG

·
·5 replies
Simen Daehlin
Simen Daehlin
Author
·Feb 18, 2022

You need to yarn install first I'm guessing? It also explains how to install sharp for windows as well

·
Usash
Usash
Feb 19, 2022

Simen Daehlin Yarn is already installed and also all the dependencies installed by yarn. but still could not connect with postgresDB which is running in docker.

·
Simen Daehlin
Simen Daehlin
Author
·Feb 19, 2022

According to the logs sharp hasn't been installed correctly. So if this Windows check the output. Usash

·
Simen Daehlin
Simen Daehlin
Author
·Feb 28, 2022

What is inside your .env for host? Usash

·
Nils K.
Nils K.
Mar 17, 2022

I needed to change the Dockerfile a bit (adding -y):

RUN apt-get update && apt-get install -y libvips-dev

and also yarn.lock was not found so I commented it out. But now I get more errors running the docker-compose up -d:

strapi | yarn run v1.22.17 strapi | $ strapi develop strapi | Knex: run strapi | $ npm install pg --save strapi | Cannot find module 'pg' strapi | Require stack: strapi | - /opt/node_modules/knex/lib/dialects/postgres/index.js strapi | - /opt/node_modules/knex/lib/knex-builder/internal/config-resolver.js strapi | - /opt/node_modules/knex/lib/knex-builder/Knex.js strapi | - /opt/node_modules/knex/lib/index.js strapi | - /opt/node_modules/knex/knex.js strapi | - /opt/node_modules/@strapi/database/lib/index.js strapi | - /opt/node_modules/@strapi/strapi/lib/Strapi.js strapi | - /opt/node_modules/@strapi/strapi/lib/index.js strapi | - /opt/node_modules/@strapi/strapi/lib/commands/develop.js strapi | - /opt/node_modules/@strapi/strapi/bin/strapi.js

·
Nils K.
Nils K.
Mar 21, 2022

Instead of node:16 I used node:14 and also I am using npm not yarn. I am using this Dockerfile (which is just a bit different from yours):

FROM node:14
# Installing libvips-dev for sharp compatability
RUN apt-get update && apt-get install -y libvips-dev
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY ./package.json ./
COPY ./package-lock.json ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN npm install
WORKDIR /opt/app
COPY ./ .
RUN npm build
EXPOSE 1337
CMD ["npm", "run", "develop"]

I added knex and pg as dev dependencies:

npm install pg knex --save-dev

Then I built my image like you did and spinned up the containers using docker-compose up -d. Everything is working fine for now and I see the "Create First Administrator" view. But if I click on that button I get a spinning icon and the error message "Warning: An error occurred while requesting the API" - nothing more. The logs show nothing unusual:

postgresDB    | 2022-03-21 19:56:28.879 UTC [1] LOG:  starting PostgreSQL 12.0 on x86_64-pc-linux-musl, compiled by gcc (Alpine 8.3.0) 8.3.0, 64-bit
postgresDB    | 2022-03-21 19:56:28.879 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgresDB    | 2022-03-21 19:56:28.879 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgresDB    | 2022-03-21 19:56:28.883 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgresDB    | 2022-03-21 19:56:28.895 UTC [21] LOG:  database system was shut down at 2022-03-21 19:56:22 UTC
postgresDB    | 2022-03-21 19:56:28.900 UTC [1] LOG:  database system is ready to accept connections
strapi        |
strapi        | > strapi-playground@0.1.0 develop /opt/app
strapi        | > strapi develop
strapi        |
strapi        | Building your admin UI with development configuration ...
strapi        | Admin UI built successfully
strapi        |
strapi        |  Project information
strapi        |
strapi        | ┌────────────────────────────────────────────────────────────────────────
strapi        | │ Time               │ Mon Mar 21 2022 19:56:33 GMT+0000 (Coordinated … │
strapi        | │ Launched in        │ 799 ms                                           │
strapi        | │ Environment        │ development                                      │
strapi        | │ Process PID        │ 34                                               │
strapi        | │ Version            │ 4.1.5 (node v14.19.1)                            │
strapi        | │ Edition            │ Community                                        │
strapi        | └────────────────────────────────────────────────────────────────────────
strapi        |
strapi        |  Actions available
strapi        |
strapi        | One more thing...
strapi        | Create your first administrator 💻 by going to the administration panel at:
strapi        |
strapi        | ┌──────────────────────────────
strapi        | │ http://localhost:1337/admin │
strapi        | └──────────────────────────────
strapi        |
strapi        | [2022-03-21 19:56:34.039] http: GET index.html (19 ms) 200
strapi        | [2022-03-21 19:56:34.130] http: GET /assets/images/logo_login.png (12 ms) 200
strapi        | [2022-03-21 19:56:34.133] http: GET /assets/images/group_people_1.png (8 ms) 200
strapi        | [2022-03-21 19:56:34.134] http: GET /assets/images/group_people_3.png (6 ms) 200
strapi        | [2022-03-21 19:56:34.134] http: GET /assets/images/group_people_2.png (5 ms) 200
strapi        | [2022-03-21 19:56:34.407] http: GET /favicon.ico (0 ms) 200
strapi        | [2022-03-21 19:56:35.169] http: GET index.html (4 ms) 200
strapi        | [2022-03-21 19:56:35.238] http: GET /assets/images/logo_login.png (2 ms) 200
strapi        | [2022-03-21 19:56:35.247] http: GET /assets/images/group_people_1.png (4 ms) 200
strapi        | [2022-03-21 19:56:35.247] http: GET /assets/images/group_people_2.png (3 ms) 200
strapi        | [2022-03-21 19:56:35.248] http: GET /assets/images/group_people_3.png (3 ms) 200
strapi        | [2022-03-21 19:56:35.514] http: GET /favicon.ico (0 ms) 200
strapi        | [2022-03-21 19:56:36.048] http: GET index.html (4 ms) 200
strapi        | [2022-03-21 19:56:36.117] http: GET /assets/images/group_people_1.png (4 ms) 200
strapi        | [2022-03-21 19:56:36.117] http: GET /assets/images/logo_login.png (2 ms) 200
strapi        | [2022-03-21 19:56:36.122] http: GET /assets/images/group_people_2.png (2 ms) 200
strapi        | [2022-03-21 19:56:36.130] http: GET /assets/images/group_people_3.png (2 ms) 200
strapi        | [2022-03-21 19:56:36.326] http: GET index.html (3 ms) 200
strapi        | [2022-03-21 19:56:36.526] http: GET index.html (3 ms) 200
strapi        | [2022-03-21 19:56:36.698] http: GET index.html (4 ms) 200
strapi        | [2022-03-21 19:56:36.878] http: GET index.html (3 ms) 200
strapi        | [2022-03-21 19:56:37.048] http: GET index.html (3 ms) 200
strapi        | [2022-03-21 19:56:37.417] http: GET index.html (3 ms) 200
strapi        | [2022-03-21 19:56:37.597] http: GET index.html (4 ms) 200
strapi        | [2022-03-21 19:56:37.778] http: GET index.html (4 ms) 200
strapi        | [2022-03-21 19:56:37.946] http: GET index.html (3 ms) 200
strapi        | [2022-03-21 19:56:38.139] http: GET index.html (4 ms) 200
strapi        | [2022-03-21 19:56:38.208] http: GET /assets/images/group_people_2.png (5 ms) 200
strapi        | [2022-03-21 19:56:38.209] http: GET /assets/images/group_people_3.png (5 ms) 200
strapi        | [2022-03-21 19:56:38.210] http: GET /assets/images/group_people_1.png (3 ms) 200
strapi        | [2022-03-21 19:56:38.210] http: GET /assets/images/logo_login.png (3 ms) 200
strapi        | [2022-03-21 19:56:38.473] http: GET /favicon.ico (0 ms) 200
strapi        | [2022-03-21 19:56:50.981] http: GET /admin (3 ms) 200
strapi        | [2022-03-21 19:56:55.216] http: GET /admin (2 ms) 200
strapi        | [2022-03-21 19:56:55.275] http: GET /admin/main.25a14c1f.js (2 ms) 200
strapi        | [2022-03-21 19:56:55.276] http: GET /admin/runtime~main.385dfcf4.js (2 ms) 200
strapi        | [2022-03-21 19:56:56.618] http: GET /admin/1856.a30bd09b.chunk.js (2 ms) 200
strapi        | [2022-03-21 19:56:56.628] http: GET /admin/497.3fcf6196.chunk.js (4 ms) 200
strapi        | [2022-03-21 19:56:56.628] http: GET /admin/1454.f065d92a.chunk.js (3 ms) 200
strapi        | [2022-03-21 19:56:56.629] http: GET /admin/4362.cf5b578d.chunk.js (2 ms) 200
strapi        | [2022-03-21 19:56:56.760] http: GET /favicon.ico (0 ms) 200
strapi        | [2022-03-21 19:56:56.777] http: GET /admin/fontawesome-css.36cff9ae.chunk.js (1 ms) 200
strapi        | [2022-03-21 19:56:56.784] http: GET /admin/en-json.2bc27a3d.chunk.js (1 ms) 200
strapi        | [2022-03-21 19:56:56.785] http: GET /admin/fr-json.a9ce0700.chunk.js (1 ms) 200
strapi        | [2022-03-21 19:56:56.854] http: GET /admin/email-translation-en-json.fa0dc92b.chunk.js (5 ms) 200
strapi        | [2022-03-21 19:56:56.855] http: GET /admin/content-type-builder-translation-fr-json.bee621f7.chunk.js (3 ms) 200
strapi        | [2022-03-21 19:56:56.855] http: GET /admin/fontawesome-css-all.3b89f909.chunk.js (4 ms) 200
strapi        | [2022-03-21 19:56:56.856] http: GET /admin/content-type-builder-translation-en-json.8034dab6.chunk.js (3 ms) 200
strapi        | [2022-03-21 19:56:56.859] http: GET /admin/email-translation-fr-json.49c3c888.chunk.js (2 ms) 200
strapi        | [2022-03-21 19:56:56.876] http: GET /admin/i18n-translation-en-json.4d823f62.chunk.js (14 ms) 200
strapi        | [2022-03-21 19:56:56.876] http: GET /admin/upload-translation-en-json.c334dd82.chunk.js (13 ms) 200
strapi        | [2022-03-21 19:56:56.877] http: GET /admin/upload-translation-fr-json.1bec79ec.chunk.js (13 ms) 200
strapi        | [2022-03-21 19:56:56.877] http: GET /admin/i18n-translation-fr-json.c6367bc9.chunk.js (13 ms) 200
strapi        | [2022-03-21 19:56:56.877] http: GET /admin/users-permissions-translation-en-json.21b0fd2f.chunk.js (12 ms) 200
strapi        | [2022-03-21 19:56:56.879] http: GET /admin/users-permissions-translation-fr-json.a2172545.chunk.js (4 ms) 200
strapi        | [2022-03-21 19:56:56.944] http: GET /admin/fontawesome-js.2639263c.chunk.js (2 ms) 200
strapi        | [2022-03-21 19:56:57.162] http: GET /admin/b997a22a2e0b87ef1fa2.ico (1 ms) 200
strapi        | [2022-03-21 19:56:57.427] http: GET /admin/cropper-css.ace19575.chunk.js (2 ms) 200
strapi        | [2022-03-21 19:57:00.538] http: GET /admin (2 ms) 200
strapi        | [2022-03-21 19:57:00.597] http: GET /admin/runtime~main.385dfcf4.js (1 ms) 200
strapi        | [2022-03-21 19:57:00.604] http: GET /admin/main.25a14c1f.js (1 ms) 200
strapi        | [2022-03-21 19:57:01.902] http: GET /favicon.ico (0 ms) 200
strapi        | [2022-03-21 19:57:02.817] http: GET /admin/1856.a30bd09b.chunk.js (1 ms) 200
strapi        | [2022-03-21 19:57:02.828] http: GET /admin/497.3fcf6196.chunk.js (4 ms) 200
strapi        | [2022-03-21 19:57:02.829] http: GET /admin/1454.f065d92a.chunk.js (4 ms) 200
strapi        | [2022-03-21 19:57:02.830] http: GET /admin/4362.cf5b578d.chunk.js (3 ms) 200
strapi        | [2022-03-21 19:57:03.102] http: GET /admin/fontawesome-css.36cff9ae.chunk.js (1 ms) 200
strapi        | [2022-03-21 19:57:03.109] http: GET /admin/fr-json.a9ce0700.chunk.js (4 ms) 200
strapi        | [2022-03-21 19:57:03.110] http: GET /admin/en-json.2bc27a3d.chunk.js (3 ms) 200
strapi        | [2022-03-21 19:57:03.240] http: GET /admin/fontawesome-css-all.3b89f909.chunk.js (1 ms) 200
strapi        | [2022-03-21 19:57:03.367] http: GET /admin/content-type-builder-translation-en-json.8034dab6.chunk.js (5 ms) 200
strapi        | [2022-03-21 19:57:03.367] http: GET /admin/content-type-builder-translation-fr-json.bee621f7.chunk.js (4 ms) 200
strapi        | [2022-03-21 19:57:03.368] http: GET /admin/upload-translation-fr-json.1bec79ec.chunk.js (4 ms) 200
strapi        | [2022-03-21 19:57:03.372] http: GET /admin/i18n-translation-en-json.4d823f62.chunk.js (6 ms) 200
strapi        | [2022-03-21 19:57:03.375] http: GET /admin/email-translation-en-json.fa0dc92b.chunk.js (6 ms) 200
strapi        | [2022-03-21 19:57:03.377] http: GET /admin/email-translation-fr-json.49c3c888.chunk.js (6 ms) 200
strapi        | [2022-03-21 19:57:03.380] http: GET /admin/i18n-translation-fr-json.c6367bc9.chunk.js (7 ms) 200
strapi        | [2022-03-21 19:57:03.383] http: GET /admin/upload-translation-en-json.c334dd82.chunk.js (7 ms) 200
strapi        | [2022-03-21 19:57:03.384] http: GET /admin/users-permissions-translation-en-json.21b0fd2f.chunk.js (6 ms) 200
strapi        | [2022-03-21 19:57:03.384] http: GET /admin/users-permissions-translation-fr-json.a2172545.chunk.js (2 ms) 200
strapi        | [2022-03-21 19:57:03.429] http: GET /admin/fontawesome-js.2639263c.chunk.js (1 ms) 200
strapi        | [2022-03-21 19:57:03.819] http: GET /admin/b997a22a2e0b87ef1fa2.ico (1 ms) 200
strapi        | [2022-03-21 19:57:04.929] http: GET /admin/cropper-css.ace19575.chunk.js (2 ms) 200
strapi        | [2022-03-21 20:01:19.848] http: GET /admin (2 ms) 200
strapi        | [2022-03-21 20:01:19.907] http: GET /admin/runtime~main.385dfcf4.js (1 ms) 200
strapi        | [2022-03-21 20:01:19.914] http: GET /admin/main.25a14c1f.js (1 ms) 200
strapi        | [2022-03-21 20:01:21.146] http: GET /favicon.ico (0 ms) 200
strapi        | [2022-03-21 20:01:21.945] http: GET /admin/1856.a30bd09b.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:21.952] http: GET /admin/497.3fcf6196.chunk.js (2 ms) 200
strapi        | [2022-03-21 20:01:21.953] http: GET /admin/1454.f065d92a.chunk.js (2 ms) 200
strapi        | [2022-03-21 20:01:21.953] http: GET /admin/4362.cf5b578d.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:22.437] http: GET /admin/fontawesome-css.36cff9ae.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:22.443] http: GET /admin/fr-json.a9ce0700.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:22.444] http: GET /admin/en-json.2bc27a3d.chunk.js (2 ms) 200
strapi        | [2022-03-21 20:01:22.518] http: GET /admin/fontawesome-css-all.3b89f909.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:22.595] http: GET /admin/content-type-builder-translation-en-json.8034dab6.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:22.614] http: GET /admin/email-translation-en-json.fa0dc92b.chunk.js (5 ms) 200
strapi        | [2022-03-21 20:01:22.615] http: GET /admin/content-type-builder-translation-fr-json.bee621f7.chunk.js (5 ms) 200
strapi        | [2022-03-21 20:01:22.615] http: GET /admin/email-translation-fr-json.49c3c888.chunk.js (4 ms) 200
strapi        | [2022-03-21 20:01:22.619] http: GET /admin/i18n-translation-en-json.4d823f62.chunk.js (6 ms) 200
strapi        | [2022-03-21 20:01:22.621] http: GET /admin/users-permissions-translation-en-json.21b0fd2f.chunk.js (5 ms) 200
strapi        | [2022-03-21 20:01:22.622] http: GET /admin/users-permissions-translation-fr-json.a2172545.chunk.js (5 ms) 200
strapi        | [2022-03-21 20:01:22.626] http: GET /admin/upload-translation-en-json.c334dd82.chunk.js (6 ms) 200
strapi        | [2022-03-21 20:01:22.627] http: GET /admin/i18n-translation-fr-json.c6367bc9.chunk.js (5 ms) 200
strapi        | [2022-03-21 20:01:22.628] http: GET /admin/upload-translation-fr-json.1bec79ec.chunk.js (3 ms) 200
strapi        | [2022-03-21 20:01:22.665] http: GET /admin/fontawesome-js.2639263c.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:22.988] http: GET /admin/b997a22a2e0b87ef1fa2.ico (1 ms) 200
strapi        | [2022-03-21 20:01:23.457] http: GET /admin/cropper-css.ace19575.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:30.351] http: GET /admin (2 ms) 200
strapi        | [2022-03-21 20:01:30.416] http: GET /admin/runtime~main.385dfcf4.js (2 ms) 200
strapi        | [2022-03-21 20:01:30.416] http: GET /admin/main.25a14c1f.js (1 ms) 200
strapi        | [2022-03-21 20:01:31.778] http: GET /favicon.ico (0 ms) 200
strapi        | [2022-03-21 20:01:32.246] http: GET /admin/1856.a30bd09b.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:32.257] http: GET /admin/4362.cf5b578d.chunk.js (5 ms) 200
strapi        | [2022-03-21 20:01:32.258] http: GET /admin/497.3fcf6196.chunk.js (5 ms) 200
strapi        | [2022-03-21 20:01:32.259] http: GET /admin/1454.f065d92a.chunk.js (3 ms) 200
strapi        | [2022-03-21 20:01:32.426] http: GET /admin/fontawesome-css.36cff9ae.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:32.434] http: GET /admin/en-json.2bc27a3d.chunk.js (2 ms) 200
strapi        | [2022-03-21 20:01:32.434] http: GET /admin/fr-json.a9ce0700.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:32.504] http: GET /admin/fontawesome-css-all.3b89f909.chunk.js (2 ms) 200
strapi        | [2022-03-21 20:01:32.527] http: GET /admin/content-type-builder-translation-en-json.8034dab6.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:32.536] http: GET /admin/content-type-builder-translation-fr-json.bee621f7.chunk.js (4 ms) 200
strapi        | [2022-03-21 20:01:32.536] http: GET /admin/email-translation-en-json.fa0dc92b.chunk.js (3 ms) 200
strapi        | [2022-03-21 20:01:32.537] http: GET /admin/email-translation-fr-json.49c3c888.chunk.js (3 ms) 200
strapi        | [2022-03-21 20:01:32.539] http: GET /admin/upload-translation-fr-json.1bec79ec.chunk.js (4 ms) 200
strapi        | [2022-03-21 20:01:32.544] http: GET /admin/users-permissions-translation-en-json.21b0fd2f.chunk.js (6 ms) 200
strapi        | [2022-03-21 20:01:32.548] http: GET /admin/i18n-translation-fr-json.c6367bc9.chunk.js (7 ms) 200
strapi        | [2022-03-21 20:01:32.550] http: GET /admin/users-permissions-translation-fr-json.a2172545.chunk.js (3 ms) 200
strapi        | [2022-03-21 20:01:32.552] http: GET /admin/upload-translation-en-json.c334dd82.chunk.js (3 ms) 200
strapi        | [2022-03-21 20:01:32.553] http: GET /admin/i18n-translation-en-json.4d823f62.chunk.js (2 ms) 200
strapi        | [2022-03-21 20:01:32.580] http: GET /admin/fontawesome-js.2639263c.chunk.js (1 ms) 200
strapi        | [2022-03-21 20:01:32.854] http: GET /admin/b997a22a2e0b87ef1fa2.ico (2 ms) 200
strapi        | [2022-03-21 20:01:33.196] http: GET /admin/cropper-css.ace19575.chunk.js (1 ms) 200

Do you know what could cause the problem?

·
·4 replies
Nils K.
Nils K.
Mar 21, 2022

I saw this on the network tab in the browser:

grafik.png

and

grafik.png I am using Strapi behind a reverse proxy (traefik) with TLS/SSL. All other network calls are correct and return status codes 20x. Only these two are resolving to localhost:1337 which can't be correct..

·
Simen Daehlin
Simen Daehlin
Author
·Mar 21, 2022

Nils K. Check what your url is set in the env setup.

·
Nils K.
Nils K.
Mar 21, 2022

Simen Daehlin Hi I already did and double-checked it: my .env (I omit the other values):

HOST=0.0.0.0
PORT=1337
URL='sub.domain.de'

and in my config/server.js:

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  url : env('URL', 'sub.domain.de'),
  app: {
    keys: env.array('APP_KEYS'),
  },
});

I still get those 2 entries with the "wrong" localhost url and the API error. Can't create my admin user..

·
Robert
Robert
Jun 23, 2022

Nils K. I have the same issue. Admin panel is using localhost and not my custom url configured in the .env. I don't have a workaround yet. Also, I cannot build the admin panel inside the docker container due to an error. I have created an issue here: forum.strapi.io/t/strapi-v4-build-and-cach…

·
欧阳维杰
欧阳维杰
Mar 25, 2022

Can not run "yarn develop" as the files in './data' directory keeps changing after the postgresDB service started. This will make the strapi constantly restarting. So I have to move the './data' directory to another position.

·
alon borin
alon borin
Apr 25, 2022

Thanks for the guide. After running docker-compose up -d I get the following error:

ERROR: for postgresDB Cannot start service postgresDB: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting "/data/myproject/data" to rootfs at "/var/lib/postgresql/data" caused: mount through procfd: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

ERROR: for postgresDB  Cannot start service postgresDB: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting "/data/myproject/data" to rootfs at "/var/lib/postgresql/data" caused: mount through procfd: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

did anyone get anything similar and solved this?

·
·3 replies
Simen Daehlin
Simen Daehlin
Author
·Apr 25, 2022

Did you mount it or does the data folder exist you are trying to bind mount it to ?

·
alon borin
alon borin
Apr 25, 2022

Simen Daehlin Can you please clarify? I didn't understand the question

·
Simen Daehlin
Simen Daehlin
Author
·May 3, 2022

Sorry for a lte reply alon borin Did you create the folder "data" it looks to me like you are trying to mount /data/myproject/data so this means the data folder needs to exist and be empty.

·
Chap
Chap
Jun 7, 2022
yarn run v1.22.19
$ strapi develop
debug: ⛔️ Server wasn't able to start properly.
error: Cannot find module '../data/data'

Not sure why it thinks to look for data within data, I only wanted to test it working on the latest image of Postgres, otherwise it's identical. here's my docker-compose.yml:

version: "3"

services:
  strapi:
    container_name: strapi
    build: .
    image: strapi:latest
    # restart: unless-stopped
    env_file: .env
    environment:
      DATABASE_CLIENT:   ${DATABASE_CLIENT}
      DATABASE_HOST:     postgresDB
      DATABASE_NAME:     ${DATABASE_NAME}
      DATABASE_USERNAME: ${DATABASE_USERNAME}
      DATABASE_PORT:     ${DATABASE_PORT}
      JWT_SECRET:        ${JWT_SECRET}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD}
      NODE_ENV:          ${NODE_ENV}
    links:
      - postgresDB:postgresDB
    volumes:
      - ./config:/opt/app/config
      - ./src:/opt/app/src
      - ./package.json:/opt/package.json
      - ./yarn.lock:/opt/yarn.lock
      - ./.env:/opt/app/.env
    ports:
      - "1337:1337"
    networks:
      - strapi
    depends_on:
      - postgresDB

  postgresDB:
    image: postgres:latest
    container_name: postgresDB
    # restart: unless-stopped
    env_file: .env
    environment:
      POSTGRES_USER:     ${DATABASE_USERNAME}
      POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
      POSTGRES_DB:       ${DATABASE_NAME}
    volumes:
      - ./data:/var/lib/postgresql/data/
    ports:
      - "5432:5432"
    networks:
      - strapi

networks:
  strapi:
    name: strapi
    driver: bridge
·
·2 replies
Simen Daehlin
Simen Daehlin
Author
·Jun 8, 2022

I think this is in strapi and not You also are using postgresDB as a link but I think this was depricated in 3 you want to use volumes instead. Else strapi won't know where the data is etc.

·
Chap
Chap
Jun 8, 2022

Simen Daehlin

So Postgres loads up fine now, so that's fixed. But I still get the cannot find module: ../data/data error within strapi. I'm still looking for any other file that would be causing this but im still confused.

version: "3.8"

services:
  strapi:
    container_name: strapi
    build: .
    image: strapi:latest
    # restart: unless-stopped
    env_file: .env
    environment:
      DATABASE_CLIENT:   ${DATABASE_CLIENT}
      DATABASE_HOST:     postgresDB
      DATABASE_NAME:     ${DATABASE_NAME}
      DATABASE_USERNAME: ${DATABASE_USERNAME}
      DATABASE_PORT:     ${DATABASE_PORT}
      JWT_SECRET:        ${JWT_SECRET}
      DATABASE_PASSWORD: ${DATABASE_PASSWORD}
      NODE_ENV:          ${NODE_ENV}
    # links:
    #   - postgres:postgres
    volumes:
      - ./config:/opt/app/config
      - ./src:/opt/app/src
      - ./package.json:/opt/package.json
      - ./yarn.lock:/opt/yarn.lock
      - ./.env:/opt/app/.env
    ports:
      - "1337:1337"
    networks:
      - strapi
    depends_on:
      - postgres

  postgres:
    image: postgres:latest
    container_name: postgres
    # restart: unless-stopped
    env_file: .env
    environment:
      POSTGRES_USER:     ${DATABASE_USERNAME}
      POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
      POSTGRES_DB:       ${DATABASE_NAME}
    volumes:
      - ./data:/var/lib/postgresql/data/
      - pgdata:/var/lib/postgresql/data
      - pgconf:/etc/postgresql
      - pglog:/var/log/postgresql
    ports:
      - "5432:5432"
    networks:
      - strapi

networks:
  strapi:
    name: strapi
    driver: bridge

volumes:
  pgdata:
    driver: local
  pgconf:
    driver: local
  pglog:
    driver: local
·
Niall
Niall
Jul 7, 2022

Hi, thanks for the tutorial, it has helped me understand quite a bit.

I have tried this on an Ubuntu machine using Yarn, and it works straight away without issue. I then commited those changes to a repo and then clone it on to a Windows machine with NPM and Docker Desktop.

Everything seems to build just fine, I can see the images and the container with both "web" and DB. However, the web image is stuck in a restart loop due to some error of connecting to the DB (like it's the wrong credentials/permissions).

Any idea?

·
·2 replies
Simen Daehlin
Simen Daehlin
Author
·Jul 7, 2022

Well only idea i can think of is that if you are using sqlite, permissions in windows and linux are different. BUT if it's built on each machine it should work fine tbh,

Seems to be maybe an issue with the setup or what you are connecting to rather then docker or your machine.

·
Niall
Niall
Jul 7, 2022

Simen Daehlin I switched it to MySQL (copying the guide), but I'm thinking that "platform" may be an issue (it's the only thing I can think of since it says "linux").

Could it be because I didn't run the initial strapi setup? I'd just assume that since all the files were created and committed, nothing else was needed. The only thing I had to re-create was the .env file.

So, an update. Docker Compose doesn't work. I've just booted up the Ubuntu machine, ran docker-compose up -d and I'm getting "server wasn't able to start properly" message, "error: knex: run".

This is a different error than on Windows, and I know Docker Desktop works, as I've been able to quickly spin up a WordPress site.

Funnily enough, the quickstart worked fine.

·
Rich Bernhardt
Rich Bernhardt
Jul 12, 2022

Hi Simen

Many thanks for this post.

Just one question. I've tried to change the port number with no success. Have you ever managed to serve dockerized strapi v4 on a port other than 1337? If so, have you employed anything else on top of the below settings?

.env

PORT=3024

docker-compose.yml

    ...
    ports:
      - "${PORT}:${PORT}"
    ...

I've changed both side of the ports' config as strapi runs on the port set in .env.

Following start strapi, the login panel shows up, but clicking the log in button returns with internal server error (500).

·
·3 replies
Simen Daehlin
Simen Daehlin
Author
·Jul 12, 2022

Hello Rich Bernhardt 👋 So I have many times, it really depends how you setup the project.

If you are ONLY using the Dockerfile and not docker compose, you will need to change the .env and also expose the correct port in Dockerfile under EXPOSE.

IF you are using docker-compose you still need to PASS port into as a variable, as I don't think the file is doing it

...
 environment:
      PORT:   ${PORT}
port:
  - "${PORT}:${PORT}"

Else docker-compose won't have access to the environmental variable etc. In docker-compose I also normally then just do

port:
  - "${PORT}:1337"

That way I can control it what the OUT port is and not what strapi uses by default I just proxy it to my own port.

·
Rich Bernhardt
Rich Bernhardt
Jul 12, 2022

Simen Daehlin Many thanks Simen, for your prompt response.

The extra line in environment PORT: ${PORT} didn't help, but extending the "strapi::cors" value in config > middlewares.js did solve the issue, although this forum does not allow me to share it.

·
Simen Daehlin
Simen Daehlin
Author
·Jul 12, 2022

Rich Bernhardt Oh that is good, if you want to send me a DM on discord find Eventyret on Strapi Discord server and I can try update the guide with what you did

·
Jens
Jens
Aug 1, 2022

Thanks for the tutorial. One thing I do not understand is the following: What's the point of having the package.json (and package-lock.json) in /opt/? Instead of just having it in /opt/app/ like the rest.

·
·1 reply
Simen Daehlin
Simen Daehlin
Author
·Aug 3, 2022

So in very simple terms. It's because it minimized attack surface of a container.

Think of it in this scenario. node_modules where your web browser / server is running it can be exploited. Meaning I can get access to the container and I can go up the chain.

If it's OUTSIDE, I get fewer exploits and have to go up further again.

·
Igor Frolov
Igor Frolov
Aug 7, 2022

Hello and thanks for this detailed tutorial! One question: should we use npm start on production instead of npm run develop? I can't see package.json, so I don't understand what strapi command executed under the hood.

·
·1 reply
Simen Daehlin
Simen Daehlin
Author
·Aug 7, 2022

Hello Igor Frolov For npm you want to use npm start it's part of NPM hence why it doesn't need a script command in package.json this is if you want to override it.

npm start will start in production

·
Lukas Mayr
Lukas Mayr
Aug 31, 2022

Hey Simen, thanks for the great tutorial. I got the server running on AWS ECS.

The only thing thats not working is sending mails. It works when I develop with strapi develop (without docker), but once it's inside a docker container, the email sending stops working. I am sending with nodemailer over Mandrill, which as I said works as long as it is not in the docker container.

In docker also the "default sender email" and the "default response email" are missing, although they are configured are also shown when developing.

If you have any insight, i would greatly appreciate an answer! all the best, lukas

·
·2 replies
Simen Daehlin
Simen Daehlin
Author
·Aug 31, 2022

Not to sure how much it will be with the tutorial. But not working while in a container might be that you have to expose the ports to allow sending emails.

When it comes to default sender etc, i think you can pass variables into it, but by default there is none i think

·
Lukas Mayr
Lukas Mayr
Aug 31, 2022

Thanks for the fast response. I figured it out. I did not put all env variables into the task definition on aws.

·