我是码头集装箱的新手。我正在尝试创建一个具有npm、节点js、chromedriver和selenium-chromedriver的docker文件,并运行我的javascript文件。在本地,我在无头铬浏览器中运行脚本。
这是我的码头文件。
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"]以下是我的码头撰写文件
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然后我使用以下命令
docker compose build //no error
docker compose up k6 nodejs那么我就得到了跟随错误。
| /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)在我的本地windows环境中,它正常工作。据我所知,我正在安装铬,铬驱动程序和硒-网络驱动程序.
少了什么?
发布于 2021-12-03 12:26:49
您不能使用这样的两行FROM。在第二个FROM行之前的所有内容都将在此之后不可用,它将启动一个新的映像。
引用FROM文档的话:
每个
FROM指令清除先前指令创建的任何状态。
您可以将文件从上一阶段复制到第二阶段,如多阶段构建文档中所述:
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替代方案:节点映像基于debian映像。您应该能够直接在映像中安装所需的内容。
https://serverfault.com/questions/1085307
复制相似问题