Docker中以人头模式执行木偶演员的问题

Docker中以人头模式执行木偶演员的问题,docker,puppeteer,Docker,Puppeteer,我对木偶演员和码头工人都是新手。在docker容器中以人头模式设置木偶演员时,我面临一个问题 Puppeteer version: 1.6.2 Platform / OS version: Docker node:8-slim Node.js version: node 8 DockerFile- FROM node:8-slim RUN apt-get update && apt-get install --no-install-recommends -y ca-certif

我对木偶演员和码头工人都是新手。在docker容器中以人头模式设置木偶演员时,我面临一个问题

Puppeteer version: 1.6.2 Platform / OS version: Docker node:8-slim Node.js version: node 8
DockerFile-

FROM node:8-slim
RUN apt-get update && apt-get install --no-install-recommends -y ca-certificates curl fontconfig fonts-liberation gconf-service git libappindicator1 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 libnss3 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 locales lsb-release unzip wget xdg-utils

RUN apt-get update && apt-get install -y wget --no-install-recommends && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && apt-get update && apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst ttf-freefont --no-install-recommends && rm -rf /var/lib/apt/lists/* \
    && apt-get purge --auto-remove -y curl && rm -rf /src/*.deb

ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init

RUN chmod +x /usr/local/bin/dumb-init

RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser && mkdir -p /home/pptruser/Downloads && chown -R pptruser:pptruser /home/pptruser && chown -R pptruser:pptruser .

USER pptruser
EXPOSE 4081/tcp
CMD [ "npm", "start" ]
申请代码:

const browser = await puppeteer.launch({
    headless: false,
    args:['--no-sandbox']
});
我正在使用Puppeter拍摄提供的url的截图。它在headless true模式下成功执行。但是,当使用headless false执行相同的脚本时,会出现以下错误:

  • 错误:无法启动chrome! [0803/070106.562113:错误:nacl\u helper\u linux.cc(310)]没有沙箱运行的nacl helper进程

  • [11104:11104:0816/105455.434188:FATAL:zyote\u host\u impl\u linux.cc(123)]没有可用的沙箱!更新您的内核,或参阅以获取有关使用SUID沙盒开发的更多信息。如果你想生活在危险的环境中,需要立即解决问题,你可以尝试使用——无沙箱

  • 你能帮我解决这个问题吗。或者,您可以分享一个示例应用程序代码,它在docker容器中以人头模式使用Puppeter进行屏幕截图。
    使用headful模式的原因:更好的性能和一些网站不允许

    检查以下
    Dockerfile
    ,阅读评论。它应该运行正常

    # First, we need to make sure all dependencies are there. If you are using docker, then the important dependencies are already present on most node images. 
    FROM node:8
    
    # To run Headful mode, you will need to have a display, which is not present in a server. 
    # To avoid this, we will use Xvfb, and create a fake display, so the chrome will think there is a display and run properly. 
    # So we just need to install Xvfb and Puppeteer related dependencies.
    RUN apt-get update && apt-get install -yq 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 x11vnc x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps xvfb
    
    # I am going to ignore dumb-init or such for now since it will add complexities to understand what is actually needed here. 
    
    # Assuming we are working on /app folder, cd into /app
    WORKDIR /app
    
    # Copy package.json into app folder
    COPY package.json /app
    
    # Install dependencies
    RUN npm install 
    
    COPY . /app
    
    # Start server on port 3000
    EXPOSE 3000
    
    # I'll also assume you are going to use root user, 
    # and your script has `--no-sandbox` and `--disable-setuid-sandbox` arguments.
    # We run a fake display and run our script.
    # Start script on Xvfb
    CMD xvfb-run --server-args="-screen 0 1024x768x24" npm start
    
    然后我用下面的命令运行它

    # build the app
    sudo docker build -t app . 
    
    # start the container, expose to network and remove after running
    sudo docker run --network=host -it app
    
    我上面使用的脚本的示例结果,可以是任何脚本

    Step 8/8 : CMD xvfb-run --server-args="-screen 0 1024x768x24" npm start
     ---> Using cache
     ---> b1319f0e68ef
    Successfully built b1319f0e68ef
    Successfully tagged scraper:latest
    
    > puppeteer-with-xvfb@1.1.0 start /app
    > node index.js
    
    Example app listening on port 3000!
    > Opening browser
    > Navigating url
    > Typing text
    > Wait for results
    > Extracted data
    > Cleaning up instances
    

    你能试试吗?我看不到您在哪里调用
    npm install
    ;你需要在那之前完成。谢谢@Aankhen我试过安装chromium。但是,它给出的错误是:包chromium浏览器不可用,但被另一个包引用。这可能意味着该软件包丢失、已过时,或者只能从另一个来源获得。另外,我还调用了npm安装。但没能放进去。不管怎样,我试着用npm安装chromium,并为木偶演员提供路径。但是,在headful模式下运行时,它再次给出了相同的错误。谢谢..它帮助:)如何将VNC转换为此?您需要一个x服务器,请检查此答案。在package.json中需要什么?