0
votes

Hello I don't know where I am wrong when trying to use the docker compose with postgress

docker compose yml:

version: "3.7"
services:
  db:
    image: postgres
    environment:
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
      POSTGRES_DB: emasa
    volumes:
      - ./pgdata:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    web:
      image: emasapg
      depends_on:
        - dbs
      ports:
        - "4000:4000"

dockerfile

FROM node as builder
WORKDIR usr/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build


FROM node
WORKDIR usr/app
COPY package*.json ./
RUN npm install --production

COPY --from=builder /usr/app/dist ./dist

COPY ormconfig.docker.json ./ormconfig.json
COPY .env . 

expose 4000
CMD node dist/src/index.js

my package.json:

{
  "name": "back-end",
  "version": "0.0.1",
  "description": "Awesome project developed with TypeORM.",
  "devDependencies": {
    "@types/express": "^4.17.3",
    "@types/graphql": "^14.5.0",
    "@types/node": "^13.9.1",
    "ts-node": "8.6.2",
    "typescript": "3.3.3333"
  },
  "dependencies": {
    "apollo-server-express": "^2.11.0",
    "express": "^4.17.1",
    "graphql": "^14.6.0",
    "pg": "^7.3.0",
    "reflect-metadata": "^0.1.13",
    "typeorm": "0.2.24"
  },
  "scripts": {
    "start": "ts-node src/index.ts"
  }
}

err:

npm ERR! missing script: build

my file structure:

enter image description here

the error starts on this line:

line 6 : RUN npm run build

Edit: had forgotten to add the package.json to the question

1
it's basically complaining about missing the build script, it tries to run build script but itis missing , Can you please update the question and post your packages.json file ? - WaLid LamRaoui
@WaLid LamRaoui done bro - user12356906

1 Answers

3
votes

It's basically complaining about missing the build script, it tries to run it, but it is missing in your package.json !

i think you should try updating your package.json file and add a build script :

{
  "name": "back-end",
  "version": "0.0.1",
  "description": "Awesome project developed with TypeORM.",
  "devDependencies": {
    "@types/express": "^4.17.3",
    "@types/graphql": "^14.5.0",
    "@types/node": "^13.9.1",
    "ts-node": "8.6.2",
    "typescript": "3.3.3333"
  },
  "dependencies": {
    "apollo-server-express": "^2.11.0",
    "express": "^4.17.1",
    "graphql": "^14.6.0",
    "pg": "^7.3.0",
    "reflect-metadata": "^0.1.13",
    "typeorm": "0.2.24"
  },
  "scripts": {
    "start": "ts-node src/index.ts",
    "build": ""  // your build script goes here, "tsc" should be fine
  }
}