1

I'm trying to install a bunch of dependencies in a docker container with Node 8 as a base image. The docker image builds and runs fine on Ubuntu but when I try it on OS X I get this error:

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:

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"]

Here are all my dependencies:

"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"
  },

Why is this happening? I thought docker was supposed to solve problems like these.

ninesalt
  • 4,054
  • 5
  • 35
  • 75
  • What line in your Dockerfile are you using to install the dependency? – NonCreature0714 Oct 31 '18 at 06:28
  • Also, there are no warnings about the path in the error message you posted, where are you getting that from? – NonCreature0714 Oct 31 '18 at 06:42
  • @noncreature0714 That's the first line it shows before it spits out the error. It's what causes it to try and install phantomjs. Using `npm install` to install dependencies as usual. – ninesalt Oct 31 '18 at 06:52
  • This looks like an SSL error, likely caused by a certificate mismatch – NonCreature0714 Oct 31 '18 at 07:03
  • After a closer look, I think the only lines relevant are the two `Error` lines – NonCreature0714 Oct 31 '18 at 07:04
  • what is the full path the the Github URL, exactly as you have it in the Dockerfile? – NonCreature0714 Oct 31 '18 at 07:07
  • @noncreature0714 What github URL? I don't have a github URL in the dockerfile but npm tries to install from this url https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2 – ninesalt Oct 31 '18 at 08:41
  • Okay, but can you put the RUN command in which tries to install Phantomjs like I’ve asked before? Just reading error messages isn’t very informative. – NonCreature0714 Oct 31 '18 at 15:18
  • @noncreature0714 it's just npm install – ninesalt Oct 31 '18 at 15:33
  • Okay, I’ve asked the same question twice now, it was my first question and the most recent, and you have not answered. At this point I think you’re being a hostile question asker, or maybe you think I’m just wasting your time. If you don’t put the RUN line from your Docker file, excluding anything proprietary of course, I’m downvoting and flagging as unclear. – NonCreature0714 Oct 31 '18 at 15:36
  • @noncreature0714 I genuinely dont understand what you're asking but I've updated the post with the dockerfile – ninesalt Oct 31 '18 at 15:37
  • Thank you, this helps me look into the issue – NonCreature0714 Oct 31 '18 at 15:44
  • One more thing, what other dependencies are in your container? If you posted your package.json would it be huge or just have Phantomjs and Mongodb? – NonCreature0714 Oct 31 '18 at 16:20
  • @noncreature0714 I dont actually explicitly install phantomjs, its a dependency of one of my dependencies. Will update the post with deps now. – ninesalt Oct 31 '18 at 16:21

2 Answers2

1
npm install phantomjs-prebuilt --phantomjs_cdnurl=http://cnpmjs.org/downloads
Nguyễn Phúc
  • 273
  • 3
  • 9
  • 3
    While this command may answer the question, providing additional context regarding why and/or how this command answers the question improves its long-term value. [How to Answer](https://stackoverflow.com/help/how-to-answer) – Elletlar Nov 13 '20 at 10:47
0

You can add one step in your docker file to install phantomjs

FROM node:8-alpine

WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . /app
EXPOSE 5000
CMD ["npm", "install", "phantom", "--save"]
CMD ["npm", "start"]

Or add the phantom dependency in the npm package.

And your phantomJS script will be like:

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();
}());
Dupinder Singh
  • 7,175
  • 6
  • 37
  • 61