My frontend shuts down after a few minutes and make me unable to use it

It is like that in the root of the project I have my docker-compose.yml file and dockerignore.

My file structure looks like this.

root:
docker-compose.yml
dockerignore
– Frontend (Typescript with nextjs + Tailwind)
– …
– Dockerfile
– Cypress

– Backend
– …
– Dockerfile

Docker-compose.yml.
version: ‘2’

services:
frontend:
build:
context: “./Frontend”
container_name: frontend
expose:
- 7075
image: “frontend:v1.2.0”
ports:
- 3000:3000
backend:
build:
context: “./Backend”
container_name: backend
image: “backend:v1.0.1”
expose:
- 7074
ports:
- 4000:4000

Frontend:

FROM node:20

WORKDIR /app

COPY mycvr/package.json .
COPY mycvr/package-lock.json* .

RUN npm i install
RUN npm next build

COPY . .

CMD [“npm”, “start”]

Backend:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base

WORKDIR /app

EXPOSE 80

EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build

WORKDIR /src

COPY [“CVR-Backend/CVR-Backend.csproj”, “./”]

COPY [“CVR-Backend.Model/CVR-Backend.Model.csproj”, “CVR-Backend.Model/”]

COPY [“CVR-Backend.Service/CVR-Backend.Service.csproj”, “CVR-Backend.Service/”]

COPY [“CVR-Backend.Data/CVR-Backend.Data.csproj”, “CVR-Backend.Data/”]

RUN dotnet restore “CVR-Backend.csproj”

COPY . .

WORKDIR “/src/CVR-Backend”

RUN dotnet build “CVR-Backend.csproj” -c Release -o /app/build

FROM build AS publish

RUN dotnet publish “CVR-Backend.csproj” -c Release -o /app/publish

FROM base AS final

WORKDIR /app

COPY --from=publish /app/publish .

ENTRYPOINT [“dotnet”, “CVR-Backend.dll”]

The problem is that every time I write this command. Then it makes an error.
docker-compose up --build

Error are: Error: Could not find a production build in the ‘/app/.next’ directory. Try building your app with ‘next build’ before starting the production server.