Home > Blockchain >  How to run what I have in package.json into Docker?
How to run what I have in package.json into Docker?

Time:04-26

I have to dockerize an app but I didn't work with docker before. It's an angular app, but every time I try to build it I got an error because it can't run a script I have in package.json because it says there is no package.json? Can someone look over my dockerfile and tells me what's wrong?

FROM node:16.13.0-alpine as builder
COPY ./ *
WORKDIR /app
RUN npm install 
RUN npm start:complete-interceptor-example

FROM nginx:1.17.10-alpine
EXPOSE 80
COPY --from=builder /app/dist/angular_task /usr/share/nginx/html


"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build:prod": "ng build opentelemetry-interceptor --prod",
    "test": "jest --coverage",
    "lint": "ng lint",
    "release": "standard-version",
    "e2e": "ng e2e",
    "cypress": "concurrently -k -p \"[{name}]\" -n \"backend,interceptor-example,cypress\" -c \"green.bold,cyan.bold,yellow.bold\" \"npm run start:backend-interceptor-example\" \"npm start interceptor-example\" \"cypress open\"",
    
    "cypress:run": "concurrently -k -s first -p \"[{name}]\" -n \"backend,interceptor-example,cypress\" -c \"green.bold,cyan.bold,yellow.bold\" \"npm run start:backend-interceptor-example\" \"npm start interceptor-example\" \"cypress run\"",
    "start:backend-interceptor-example": "node ./projects/interceptor-example/src/backend-api.js",
    "start:complete-interceptor-example": "concurrently -k -p \"[{name}]\" -n \"backend,interceptor-example\" -c \"green.bold,cyan.bold\" \"npm run start:backend-interceptor-example\" \"npm start interceptor-example\"",  
    "compodoc": "npx compodoc -t -p projects/opentelemetry-interceptor/tsconfig.lib.json --theme material -d ./docs -n \"OpenTelemetry Angular Interceptor\""
  },

this is inside the package.json and this is my folder structure

enter image description here

I think I copy wrong the files. I can't find anything on Google that might work. Thank you for your time!

CodePudding user response:

WORKDIR changes the current dir, so when you COPY the files first and then set the WORKDIR, you copy the files to another directory than the workdir.

When you want your app to be served by Nginx, you also need to build, so you can copy the built app to Nginx.

Try this

FROM node:16.13.0-alpine as builder
WORKDIR /app
COPY . .
RUN npm install 
RUN npm run build

FROM nginx:1.17.10-alpine
EXPOSE 80
COPY --from=builder /app/dist /usr/share/nginx/html
  • Related