gpt4 book ai didi

docker - 通过 no-sandbox 但仍然出现错误 'Running as root without --no-sandbox is not supported.`

转载 作者:行者123 更新时间:2023-12-05 06:06:32 43 4
gpt4 key购买 nike

我能够使用 node 用户并使用 --cap-add=SYS_ADMIN 设置沙箱使其正常工作,但 AWS ECS Fargate 不支持添加 SYS_ADMIN 作为 linux 参数。因此,我试图将 no--sandbox 传递给 puppeteer,这样我就可以以 root 身份运行,但仍然收到错误消息 Running as root without --no-sandbox is not supported.

环境

  • puppeteer 版本:1.20.0
  • 平台/操作系统版本:Docker/Debian 9.12
  • Node.js 版本:10.21

重现步骤

如果我执行到 Docker 容器并显式运行 node puppeteer.js 我不会收到错误,但是如果我通过 Postman (http://localhost:8081) 向我的容器发出请求我收到错误。

Dockerfile

FROM node:10.21

RUN apt-get update && \
apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 \
libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 \
libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 \
libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 \
libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates \
fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget


# Create app directory
WORKDIR /usr/src/app

# Bundle app source
COPY . .

# Install app dependencies
RUN npm install

# Tried running as node user
#USER node

# Provide google authentication credentials to your application code
ENV GOOGLE_APPLICATION_CREDENTIALS=/usr/src/app/google/keys.json

CMD [ "npm", "start" ]

Puppeteer.js

const puppeteer = require('puppeteer');

/**
* Initializes and returns a puppeteer instance
* @name {getPuppeteerInstance}
* @returns {Promise} resolves with puppeteer instance
*/
module.exports = async () => {
try {
const options = {
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
defaultViewport: {
width: 1440,
height: 900,
},
timeout: 0, // 0ms timeout is no timeout
};
const browser = await puppeteer.launch(options);
const page = await browser.newPage(); ``

page.setDefaultTimeout(0);
page.setDefaultNavigationTimeout(0);

return { browser, page };
} catch (error) {
console.log(`error`, error);

return {};
}
};

预期的结果是什么?通过传递 --no-sandbox,我希望能够以 root 身份启动 puppeteer,而无需设置没有问题的沙箱。

会发生什么?

error Error: Failed to launch chrome!
blackbox-app | [0113/220603.530554:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

最佳答案

同样的问题,尝试了一些方法来解决这个问题

docker 文件

启用内核

RUN echo 'kernel.unprivileged_userns_clone=1' > /etc/sysctl.d/userns.conf

添加用户并使用该用户启动 chromium

RUN adduser --disabled-password --disabled-login puppeteer

USER puppeteer

CMD ["your command"]

在 docker-compose.yaml 中

    cap_add:
- SYS_ADMIN

关于docker - 通过 no-sandbox 但仍然出现错误 'Running as root without --no-sandbox is not supported.`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65726398/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com