Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Crashin Angular project docker container

I have docker container for angular project, using node 18;
Dockerfile:

FROM node:18

WORKDIR /app

COPY package*.json ./
RUN npm update

RUN npm install

COPY . .

EXPOSE 4200

CMD ["ng", "serve", "--host", "0.0.0.0", "--port", "4200"]

problem is when I run sudo docker-copmose build, its good but then i try sudo docker-compose up it has an errors :

auralab-angular | node:internal/modules/cjs/loader:1080
auralab-angular |   throw err;
auralab-angular |   ^
auralab-angular | 
auralab-angular | Error: Cannot find module '/app/ng'
auralab-angular |     at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
auralab-angular |     at Module._load (node:internal/modules/cjs/loader:922:27)
auralab-angular |     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
auralab-angular |     at node:internal/main/run_main_module:23:47 {
auralab-angular |   code: 'MODULE_NOT_FOUND',
auralab-angular |   requireStack: []
auralab-angular | }
auralab-angular | 
auralab-angular | Node.js v18.18.2

I am using google-cloud unbutu machine, but i dont know error reason.
docker-compose.yaml:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

angular:
    image: auralab-angular:latest
    container_name: auralab-angular
    build:
      context: ./client
      dockerfile: Dockerfile
    volumes:
      - ./client:/app
    ports:
      - "4200:4200"
    command: ["ng", "serve", "--host", "0.0.0.0", "--port", "4200"]
    depends_on:
      - django

structure is :

project:
|___client:
|_______Dockerfile
|_______other files;
|___docker-compose.yaml

>Solution :

You’ll need to install the Angular CLI inside your Docker container.

FROM node:18

WORKDIR /app

COPY package*.json ./

# Install Angular CLI globally
RUN npm install -g @angular/cli

RUN npm install

COPY . .

EXPOSE 4200

CMD ["ng", "serve", "--host", "0.0.0.0", "--port", "4200"]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading