Why is the suggested docker project structure different to documentation

System Information
  • Strapi Version: 4.20.2
  • Operating System: Docker node:20-alpine3.18 running on MacOS 14.1.1
  • Database: Postgres
  • Node Version: v20.11.1
  • NPM Version: 10.2.4 (though using PNPM 8.15.3)

I’ve been adapting the Docker guidelines to suit my project, and have noticed that the suggested Docker configuration moves the package.json, lock file and node_modules to a different place than is described in the Project Structure docs.

In the Dockerfile, the package.json, package-lock.json, and node_modules are located in the /opt/ dir, whereas the rest of the strapi files are located in /opt/app :

COPY package.json package-lock.json ./
# ...
ENV PATH /opt/node_modules/.bin:$PATH
WORKDIR /opt/app
COPY . .
RUN npm run build

However in the documented Project Structure, everything resides under the project root:

. # root of the application
├──── .strapi # auto-generated folder — do not update manually
├──── .tmp
├──── build # build of the admin panel
├──── config # API configurations
├──── database
├──── node_modules # npm packages used by the project
├──── public # files accessible to the outside world
├──── src
├ .env
└ package.json

I can’t find an explanation for this, does anyone know why the location might be different for the suggested Dockerfile, and whether it actually matters?


I can see one benefit which is that is avoids running the chown on all of node_modules here:

RUN chown -R node:node /opt/app