How can I use Angular 19 SSR with Docker?

Discussão em 'Angular' iniciado por Ncls7523, Fevereiro 4, 2025.

  1. Ncls7523

    Ncls7523 Guest

    I created a fresh Angular 19 SSR app and I would like to use it with Docker.

    But I faced a lot of issues.

    My Dockerfile :

    FROM node:23

    WORKDIR /app

    COPY package*.json ./

    RUN npm install

    RUN npm install -g @angular/cli@latest

    COPY . .

    RUN npm run build:ssr

    EXPOSE 4200

    CMD ["npm", "run", "serve:ssr"]


    Script form package.json

    "scripts": {
    "ng": "ng",
    "build:ssr": "ng build && ng run chapter-alert-front:server",
    "serve": "ng serve",
    "serve:ssr": "node dist/chapter-alert-front-server/main.js",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "serve:ssr:chapter-alert-front": "node dist/chapter-alert-front/server/server.mjs"
    },


    My angular.json

    {
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
    "chapter-alert-front": {
    "projectType": "application",
    "schematics": {
    "@schematics/angular:component": {
    "style": "scss"
    }
    },
    "root": "",
    "sourceRoot": "src",
    "prefix": "app",
    "architect": {
    "build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
    "outputPath": "dist/chapter-alert-front",
    "index": "src/index.html",
    "main": "src/main.ts",
    "polyfills": ["zone.js"],
    "tsConfig": "tsconfig.app.json",
    "inlineStyleLanguage": "scss",
    "assets": [
    {
    "glob": "**/*",
    "input": "public"
    }
    ],
    "styles": ["src/styles.scss"],
    "scripts": []
    },
    "configurations": {
    "production": {
    "budgets": [
    {
    "type": "initial",
    "maximumWarning": "500kB",
    "maximumError": "1MB"
    },
    {
    "type": "anyComponentStyle",
    "maximumWarning": "4kB",
    "maximumError": "8kB"
    }
    ],
    "outputHashing": "all"
    },
    "development": {
    "optimization": false,
    "extractLicenses": false,
    "sourceMap": true
    }
    },
    "defaultConfiguration": "production"
    },
    "server": {
    "builder": "@angular-devkit/build-angular:server",
    "options": {
    "outputPath": "dist/chapter-alert-front-server",
    "main": "src/main.server.ts",
    "tsConfig": "tsconfig.app.json"
    }
    },
    "serve": {
    "builder": "@angular-devkit/build-angular:dev-server",
    "configurations": {
    "production": {
    "buildTarget": "chapter-alert-front:build:production"
    },
    "development": {
    "buildTarget": "chapter-alert-front:build:development"
    }
    },
    "defaultConfiguration": "development"
    },
    "extract-i18n": {
    "builder": "@angular-devkit/build-angular:extract-i18n"
    },
    "test": {
    "builder": "@angular-devkit/build-angular:karma",
    "options": {
    "polyfills": ["zone.js", "zone.js/testing"],
    "tsConfig": "tsconfig.spec.json",
    "inlineStyleLanguage": "scss",
    "assets": [
    {
    "glob": "**/*",
    "input": "public"
    }
    ],
    "styles": ["src/styles.scss"],
    "scripts": []
    }
    }
    }
    }
    }
    }


    I really struggling to undestand how to use the SSR part of angular with Docker. What i'm missing ? Or I doing wrong ?

    My goal is to just start the app like I was in my local computer.

    With the above code, all work fine but the app doesn't lunch. That look normal because the code just run a node app.js ... Which part I need to change ?

    If anyone can please, help me a bit, thanks a lot.

    Continue reading...

Compartilhe esta Página