无法在 docker 中运行 selenium - 服务器提前终止,状态为 255

Can not run selenium in docker - Server terminated early with status 255

提问人:Nikita 提问时间:10/6/2023 最后编辑:Nikita 更新时间:10/6/2023 访问量:120

问:

我无法在 docker 中运行 selenium。运行命令后,出现错误:docker run --name selenium-docker --rm selenium-docker

Run check
Selenium Manager binary found at /app/node_modules/selenium-webdriver/bin/linux/selenium-manager
Driver path: /root/.cache/selenium/chromedriver/linux64/117.0.5938.149/chromedriver
Browser path: /root/.cache/selenium/chrome/linux64/117.0.5938.149/chrome
/app/node_modules/selenium-webdriver/remote/index.js:259
                reject(Error(e.message))
                       ^

Error: Server terminated early with status 255
    at /app/node_modules/selenium-webdriver/remote/index.js:259:24
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v20.8.0

我的索引 .js 文件

const {Builder, Browser} = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36'

const check = async () => {
    console.log('Run check')
    const chromeOptions =  new chrome.Options();
    const driver = new Builder()
        .forBrowser(Browser.CHROME)
        .setChromeOptions(
            chromeOptions
                .addArguments('--ignore-ssl-errors=yes')
                .addArguments('--ignore-certificate-errors')
                .addArguments('--no-sandbox')
                .addArguments('--headless=new')
                .addArguments('--window-size=1920,1080')
                .addArguments(`user-agent=${userAgent}`)
        )
        .build();

    await driver.get('https://www.google.com');
    console.log('loaded!');
}

Docker文件

FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["npm", "start"]

如果我在本地运行 index.js,一切都很好。可能出了什么问题?似乎我错过了什么。

节点 .js docker selenium-webdriver

评论


答: 暂无答案