Search code examples
dockerautomationdockerfileplaywright

Getting npm: command not found in running docker containter


I am getting an error below when running the docker container

2024-02-01 14:23:28 ./src/portal/run_tests.sh: line 6: npm: command not found 2024-02-01 14:23:28 ./src/portal/run_tests.sh: line 9: npx: command not found 2024-02-01 14:23:28 ./src/portal/run_tests.sh: line 12: npm: command not found

This the content of my shell script: run_tests.sh

#!/bin/bash

#whatever commands you need to run to execute tests for feature branch

#Install dependencies
npm ci

#Install Playwright Browsers
npx playwright install --with-deps

#Run Portal tests on Dev environment
npm run env:dev

This is the content of my Docker file

FROM docker/whalesay:latest

RUN curl -sL https://deb.nodesource.com/setup_7.x | bash
RUN apt-get install -y nodejs

WORKDIR /app
COPY . .
ENTRYPOINT [ "./src/portal/run_tests.sh" ]

This is the steps I ran:

docker build . --file Dockerfile -t qe-portal-tests
docker run -t -d --name qe-portal-tests-container qe-portal-tests /bin/bash

After running the second line, I am getting the error I posted above in the logs in Docker dashboard


Solution

  • Not sure why you are using the docker/whalesay image: I'm replacing that with the node image. Try this.

    🗎 Dockerfile

    FROM node:latest
    
    WORKDIR /app
    COPY . .
    
    RUN chmod u+x /app/src/portal/run_tests.sh
    
    ENTRYPOINT [ "./src/portal/run_tests.sh" ]
    

    🗎 run_tests.sh (which resides in ./src/portal/)

    #!/bin/bash
    
    npm ci
    
    npm install playwright --with-deps
    
    npm run env:dev