title: npm script fails with sh: 1: <command>: not found in docker container
body: <h1>Question</h1>
  
  <p>When running <code>npm run start:debug</code> command inside a docker container, I get this error:</p>
  
  <pre><code># npm run start:debug
  
  &gt; api@0.0.0 start:debug /usr/src/api
  &gt; nest start -e "node --inspect-brk 0.0.0.0:9229" --watch -p tsconfig.json
  
  sh: 1: nest: not found
  npm ERR! code ELIFECYCLE
  npm ERR! syscall spawn
  npm ERR! file sh
  npm ERR! errno ENOENT
  npm ERR! api@0.0.0 start:debug: `nest start -e "node --inspect-brk 0.0.0.0:9229" --watch -p tsconfig.json`
  npm ERR! spawn ENOENT
  </code></pre>
  
  <p>Running <code>npm ls --depth=0</code> shows that I have <code>@nestjs/cli</code> installed:</p>
  
  <pre><code># npm ls --depth=0
  api@0.0.0 /usr/src/api
  +-- @nestjs/cli@6.14.2
  +-- @nestjs/common@6.11.11
  ...
  </code></pre>
  
  <p>Why isn't the nest cli binary being found?</p>
  
  <h1>My Setup</h1>
  
  <p>This is how I launch the shell:</p>
  
  <p><code>docker-compose -f docker-compose-base.yml -f docker-compose-dev.yml run api /bin/sh</code></p>
  
  <p>My docker-compose files:</p>
  
  <pre><code># -base
  version: '3'
  
  services:
    api:
      build: .
      restart: on-failure
      volumes:
        - /usr/src/api/node_modules
      container_name: api
  
  
  # -dev
  version: '3'
  
  networks:
    # Use lb_lbnet network created by the load balancer repo (lb)
    # We do this because we need the load balance to resolve container names defined here to forward traffic
    # This is only needed for dev
    default:
      external:
        name: lb_lbnet
  
  services:
    db:
      image: postgres:11
      container_name: db
      restart: always
      env_file:
        - ./db.env # uses POSTGRES_DB and POSTGRES_PASSWORD to create a fresh db with a password when first run
      volumes:
        - ./postgres-data:/var/lib/postgresql/data
        # only used to upload DB dump:
        # - ./backup:/tmp/backup
  
    api:
      restart: 'no'
      build:
        context: .
        args:
          NODE_ENV: development
      depends_on:
        - db
      ports:
        - 9229:9229
      volumes:
        - ./:/usr/src/api
        - ./node_modules:/usr/src/api/node_modules
        # enable to debug hgezim-express-shopify-auth
        - ../../hgezim-express-shopify-auth:/usr/hgezim-express-shopify-auth
      env_file:
        - .env
      command: /bin/bash -c 'echo "Starting" &amp;&amp; npm install &amp;&amp; npm run start:debug'
  </code></pre>
  
  <p>My Dockerfile:</p>
  
  <pre><code>FROM node:12
  
  WORKDIR /usr/src/api
  
  COPY package*.json ./
  
  ARG NODE_ENV=production
  ENV NODE_ENV=${NODE_ENV}
  
  RUN npm install # &amp;&amp; npm ls --depth=0 # commented this out since it returns non-zero exit code
  
  COPY . .
  
  VOLUME [ "/usr/src/api/node_modules" ]
  
  RUN ["/usr/local/bin/npm", "run","lint"]
  RUN ["/usr/local/bin/npm", "run","build"]
  
  # not using an execution list here so we get shell variable substitution
  CMD /bin/bash -c 'npm run start:$NODE_ENV'
  </code></pre>