栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Docker中以headful模式执行人偶的问题

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Docker中以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 /appWORKDIR /app# Copy package.json into app folderCOPY package.json /app# Install dependenciesRUN npm installCOPY . /app# Start server on port 3000EXPOSE 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 XvfbCMD xvfb-run --server-args="-screen 0 1024x768x24" npm start

然后我用以下命令运行它,

# build the appsudo docker build -t app .# start the container, expose to network and remove after runningsudo docker run --network=host -it app

我上面使用的脚本的示例结果,可以是任何脚本,

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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/426419.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号