0

I am a novice in a docker container. I am trying to create a docker file that has npm, node js, chromedriver and selenium-chromedriver and run my javascript file. In my local , I run the script in the headless chrome browser.

Here is my docker file.

FROM ubuntu:20.04

USER root

WORKDIR /home/app

RUN apt-get update
  
RUN apt-get install git --yes

# Install Google Chrome
RUN apt-get install wget
RUN apt-get install ./google-chrome*.deb --yes
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -P /usr/bin/ && \ dpkg --unpack google-chrome-stable_current_amd64.deb && \ apt-get install -f -y,

#FROM node:14.18.0
FROM node:17.2.0
USER root
ENV NODE_ENV=production
WORKDIR /LoadTesting
COPY ["/LoadTesting/package.json", "."]
RUN npm install
RUN npm ci
RUN npm install nodejs
RUN npm install mocha -g
RUN npm install chromedriver -g --unsafe-perm
RUN npm install selenium-webdriver


COPY /LoadTesting .
COPY /LoadTesting/test .
CMD ["node", "./test/script.js"]

following is my docker compose file

version: '3.7'

services:
  k6:
    image: "loadimpact/k6:0.32.0"
    volumes:
      - "./loadtesting:/scripts"
  nodejs:
    build:
      context: ./
      dockerfile: k6-nodejs-dockerfile
    volumes:
      - '.loadtesting:/loadtesting'

volumes:
  grafana-storage:
  prometheus-data:
    external: true

Then I use following commands

docker compose build //no error
docker compose up k6 nodejs

Then I get following error.

| /LoadTesting/node_modules/selenium-webdriver/remote/index.js:248
-nodejs-1  |                 reject(Error(e.message))
-nodejs-1  |                        ^
-nodejs-1  |
-nodejs-1  | Error: Server terminated early with status 127
-nodejs-1  |     at /LoadTesting/node_modules/selenium-webdriver/remote/index.js:248:24
-nodejs-1  |     at processTicksAndRejections (node:internal/process/task_queues:96:5)

In my local windows environment, its working properly. As far as I know, I am installing chrome, chrome driver and selenium-webdriver.

What is missing?

Jay
  • 3
  • 3

1 Answers1

0

You can't use two FROM lines like that. Everything before the second FROM line will not be available after that, it will start a new image.

Quote from the FROM documentation:

Each FROM instruction clears any state created by previous instructions.

You can copy files from the previous stage over to the second one, as described in the multi-stage build documentation:

FROM golang:1.16 AS builder
# do your stuff
FROM alpine:latest
COPY --from=builder /go/src/github.com/alexellis/href-counter/app ./
# do more stuff

Alternative: The node image is based on a debian image. You should be able to install what you need directly in that image.

Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79
  • @jay please don't edit answers of other people like that. You can comment on your own question to request clarifications, and you can edit your own question to provide more information. But don't edit your question in a way that would render answers completely invalid. Sometimes it's better to ask a new question if a follow up problem arises. – Gerald Schneider Dec 03 '21 at 13:33
  • I am sorry. That was a mistake – Jay Dec 03 '21 at 13:36