首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在docker容器内的路径中找不到Phantomjs

在docker容器内的路径中找不到Phantomjs
EN

Stack Overflow用户
提问于 2018-10-31 05:56:08
回答 2查看 2.3K关注 0票数 0

我正尝试在一个docker容器中安装一堆依赖项,使用Node8作为基础镜像。docker镜像在Ubuntu上构建和运行得很好,但当我在OS X上尝试它时,我得到了这个错误:

代码语言:javascript
复制
Error making request.
Error: getaddrinfo EAI_AGAIN github.com:443
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)

Please report this full log at https://github.com/Medium/phantomjs
npm WARN backend@1.0.0 No repository field.
npm WARN backend@1.0.0 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! phantomjs-prebuilt@2.1.16 install: `node install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the phantomjs-prebuilt@2.1.16 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Dockerfile:

代码语言:javascript
复制
FROM node:8-alpine

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . /app
# ADD MONGOURL ENV HERE
EXPOSE 5000
CMD ["npm", "start"]

下面是我的所有依赖项:

代码语言:javascript
复制
"dependencies": {
    "body-parser": "^1.18.3",
    "compression": "^1.7.3",
    "cors": "^2.8.4",
    "express": "^4.16.4",
    "html-parse-stringify": "^1.0.3",
    "jsonwebtoken": "^8.3.0",
    "lodash": "^4.17.11",
    "mongoose": "^5.3.3",
    "morgan": "^1.9.1",
    "passport": "^0.4.0",
    "passport-facebook": "^2.1.1",
    "passport-google-oauth": "^1.0.0",
    "query-string": "^6.2.0",
    "request": "^2.88.0",
    "signalr-client": "0.0.19",     // 90% sure this is the one installs phantomjs
    "socket.io": "^2.1.1",
    "swagger-ui-express": "^4.0.1"
  },

为什么会发生这种情况?我以为docker应该能解决这样的问题。

EN

回答 2

Stack Overflow用户

发布于 2020-05-15 00:29:02

您可以在docker文件中添加一个步骤来安装phantomjs

从节点:8-高山

代码语言:javascript
复制
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . /app
EXPOSE 5000
CMD ["npm", "install", "phantom", "--save"]
CMD ["npm", "start"]

或者在npm包中添加虚拟依赖项。

您的phantomJS脚本将如下所示:

代码语言:javascript
复制
const phantom = require('phantom');

(async function() {
    const instance = await phantom.create();
    const page = await instance.createPage();
    await page.on("onResourceRequested", function(requestData) {
        console.info('Requesting', requestData.url)
    });

    const status = await page.open('https://stackoverflow.com/');
    console.log(status);

    const content = await page.property('content');
    console.log(content);

    await instance.exit();
}());
票数 0
EN

Stack Overflow用户

发布于 2020-11-13 18:02:14

代码语言:javascript
复制
npm install phantomjs-prebuilt --phantomjs_cdnurl=http://cnpmjs.org/downloads
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53073438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档