Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does RUN in dockerfile not process npx , node commands

I noticed whenever I build the docker image it builds, but fails to run npx and node commands in the dockerfile for the image. When the container for the image is up, I would not see a generate-typings.js file at all. But when I enter the container to run the script it works.

DockerFile

FROM node:14.17.6 as base

WORKDIR /usr/src/app

#copy package.json to docker container
COPY package.json ./

#For schema back end
COPY prisma/. /usr/src/app/prisma/.
COPY ts*.json ./
#For the database connection
COPY .env ./
#install package.json dependency
RUN npm i
#transfer code files
COPY ./src /usr/src/app/src/
#generate typings for graphql -- line not running in image
RUN npx - tsc --skipLibCheck /usr/src/app/src/gql/generate-typings.ts
#update the scheme 
RUN node /usr/src/app/src/gql/generate-typings.js

#include nestjscli globally
RUN npm install -g @nestjs/cli
#generate
RUN npx prisma generate

docker-compose file

version: "3.9"

services: 
  api:
    container_name: back_end_api
    build: 
      context: .
      dockerfile: Dockerfile
      target: base
    tty: true
    expose:
      - '4000'
    ports: 
      - "4000:4000"
    volumes:
      - ./src:/usr/src/app/src  #persist src folder to host machine
    networks:
      - emNetwork
    command: npm run dev
networks:
  emNetwork:  
like image 419
adeniran827 Avatar asked Apr 24 '26 03:04

adeniran827


1 Answers

Running the command in array format worked for me,

Try this:

RUN ["npx","- tsc","--skipLibCheck","/usr/src/app/src/gql/generate-typings.ts"]

Insetad of:

RUN npx - tsc --skipLibCheck /usr/src/app/src/gql/generate-typings.ts
like image 165
Piyush Manwar Avatar answered Apr 25 '26 19:04

Piyush Manwar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!