Strapi v4 build and .cache folders does not exists inside Docker container

System Information
  • Strapi Version: 4.2.0
  • Operating System: MacOS
  • Database: MariaDB
  • Node Version: 16.15.1
  • NPM Version: 8.12.1

According to this github issue, I’m following this article to set up Strapi and Docker.

My Strapi is behind a Nginx so I need to set up a custom url for the public url of the server.

After spinning up the Strapi in Docker, my admin panel is blank because it’s pointing to localhost address instead of my custom url.

Screen Shot 2022-06-23 at 3.45.32 PM

I have tried to build Strapi inside the Docker container but I receive an error.

Notice that the build/ and .cache/ folders are not there.

This is my configuration:

config/server.js

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

Dockerfile (the same as the example from the article)

FROM node:14

# Installing libvips-dev for sharp Compatability
RUN apt-get update && apt-get install libvips-dev -y

ARG NODE_ENV=production
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

COPY ./ .

RUN npm run build

EXPOSE 1337

CMD ["npm", "run", "start"]

docker-compose.yml

version: '3.8'

services:

  strapi:
    image: username/my-strapi-image
    container_name: strapi
    depends_on:
      - mariadb
    env_file:
      - envs/strapi.env
    networks:
      - backend

strapi.env

HOST=0.0.0.0
PORT=1337
URL=https://cms.example.com
APP_KEYS=123

Questions:

  1. What can I do to build the admin panel inside the Docker container?
  2. Do I have something wrong with my configurations files? I thought that Strapi will read the env variables from docker-compose and build the admin from scratch before running the npm run start command.

Any advice or help would be appreciated.