0

I am running mode-red module of nodejs with docker-compose in following way:

version: "3"
services:
    node-red:
        build: node-red/.
        container_name: mynodered
        network_mode: "host"
        volumes:
         - $PWD/data/node:/data
        ports:
         - "1880:1880"

I have placed the following docker file in folder node-red:

FROM nodered/node-red-docker:v8
RUN npm i -S basic-auth bcryptjs body-parser cheerio clone cookie cookie-parser cors cron express express-session follow-redirects fs-extra fs.notify hash-sum i18next is-utf8 js-yaml json-stringify-safe jsonata media-typer memorystore mqtt multer mustache node-red-contrib-cloudera node-red-contrib-confluent node-red-contrib-ksql node-red-contrib-python-function node-red-contrib-rdkafka node-red-contrib-s3 node-red-node-email node-red-node-feedparser node-red-node-rbe node-red-node-twitter nopt oauth2orize on-headers passport passport-http-bearer passport-oauth2-client-password raw-body semver sentiment uglify-js when ws xml2js && npm i -D chromedriver grunt grunt-chmod grunt-cli grunt-concurrent grunt-contrib-clean grunt-contrib-compress grunt-contrib-concat grunt-contrib-copy grunt-contrib-jshint grunt-contrib-uglify grunt-contrib-watch grunt-jsonlint grunt-mocha-istanbul grunt-nodemon grunt-sass grunt-simple-mocha grunt-webdriver istanbul mocha should sinon supertest wdio-chromedriver-service wdio-mocha-framework wdio-spec-reporter webdriverio && npm i -O bcrypt

When i am building image explicitly from this docker file in following way,its working fine

docker build --network host -t dvnode .

But when i am using docker-compose,it gives following error:

docker-compose up
Building node-red
Step 1/2 : FROM nodered/node-red-docker:v8
 ---> 8d6fdff59c2c
Step 2/2 : RUN npm i -S basic-auth bcryptjs body-parser cheerio clone cookie cookie-parser cors cron express express-session follow-redirects fs-extra fs.notify hash-sum i18next is-utf8 js-yaml json-stringify-safe jsonata media-typer memorystore mqtt multer mustache node-red-contrib-cloudera node-red-contrib-confluent node-red-contrib-ksql node-red-contrib-python-function node-red-contrib-rdkafka node-red-contrib-s3 node-red-node-email node-red-node-feedparser node-red-node-rbe node-red-node-twitter nopt oauth2orize on-headers passport passport-http-bearer passport-oauth2-client-password raw-body semver sentiment uglify-js when ws xml2js && npm i -D chromedriver grunt grunt-chmod grunt-cli grunt-concurrent grunt-contrib-clean grunt-contrib-compress grunt-contrib-concat grunt-contrib-copy grunt-contrib-jshint grunt-contrib-uglify grunt-contrib-watch grunt-jsonlint grunt-mocha-istanbul grunt-nodemon grunt-sass grunt-simple-mocha grunt-webdriver istanbul mocha should sinon supertest wdio-chromedriver-service wdio-mocha-framework wdio-spec-reporter webdriverio && npm i -O bcrypt
 ---> Running in a69e76805cc1
npm WARN registry Unexpected warning for https://registry.npmjs.org/: Miscellaneous Warning EAI_AGAIN: request to https://registry.npmjs.org/basic-auth failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm WARN registry Using stale package data from https://registry.npmjs.org/ due to a request error during revalidation.
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/node-red-contrib-cloudera failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org:443

npm ERR! A complete log of this run can be found in:
npm ERR!     /usr/src/node-red/.npm/_logs/2018-05-03T08_10_08_489Z-debug.log
ERROR: Service 'node-red' failed to build: The command '/bin/sh -c npm i -S basic-auth bcryptjs body-parser cheerio clone cookie cookie-parser cors cron express express-session follow-redirects fs-extra fs.notify hash-sum i18next is-utf8 js-yaml json-stringify-safe jsonata media-typer memorystore mqtt multer mustache node-red-contrib-cloudera node-red-contrib-confluent node-red-contrib-ksql node-red-contrib-python-function node-red-contrib-rdkafka node-red-contrib-s3 node-red-node-email node-red-node-feedparser node-red-node-rbe node-red-node-twitter nopt oauth2orize on-headers passport passport-http-bearer passport-oauth2-client-password raw-body semver sentiment uglify-js when ws xml2js && npm i -D chromedriver grunt grunt-chmod grunt-cli grunt-concurrent grunt-contrib-clean grunt-contrib-compress grunt-contrib-concat grunt-contrib-copy grunt-contrib-jshint grunt-contrib-uglify grunt-contrib-watch grunt-jsonlint grunt-mocha-istanbul grunt-nodemon grunt-sass grunt-simple-mocha grunt-webdriver istanbul mocha should sinon supertest wdio-chromedriver-service wdio-mocha-framework wdio-spec-reporter webdriverio && npm i -O bcrypt' returned a non-zero code: 1
Arshanvit
  • 417
  • 1
  • 7
  • 28
  • The error implies that the docker container failed to look up the ip address of a hostname via DNS. https://stackoverflow.com/questions/40182121/error-getaddrinfo-eai-again – hardillb May 03 '18 at 09:04
  • @hardillb I agree,then issue should also come on running explicitly in network_mode as mentioned above. – Arshanvit May 03 '18 at 09:34
  • Docker compose features on container-level (not building images), so I think the `network_mode` is consumed by `docker run` which is implicitly called when you run `docker-compose up`. See https://docs.docker.com/engine/reference/run/#network-settings. – momocow May 03 '18 at 10:40
  • @momocow, I tried `docker-compose build` too,Same error – Arshanvit May 03 '18 at 11:02
  • I mean any configuration you write in a `docker-compose.yml` is consumed by `docker run` since docker compose features especially on **container level**. I haven't found yet any equivalence config to achieve this in a `docker-compose.yml` for a building routine. – momocow May 04 '18 at 02:03
  • It seems to be an error with DNS while building an image. To work around it, how about manually adding NPM registry host to `/etc/hosts` in the Dockerfile? `RUN echo "151.101.52.162 registry.npmjs.org" >> /etc/hosts` – momocow May 04 '18 at 02:10
  • @momocow It is giving issue `FROM nodered/node-red-docker:v8 ---> 8d6fdff59c2c Step 2/3 : RUN echo "151.101.52.162 registry.npmjs.org" >> /etc/hosts ---> Running in 477a467f6fd2 /bin/sh: 1: cannot create /etc/hosts: Permission denied ERROR: Service 'node-red' failed to build: The command '/bin/sh -c echo "151.101.52.162 registry.npmjs.org" >> /etc/hosts' returned a non-zero code: 2` – Arshanvit May 04 '18 at 09:23
  • `cannot create /etc/hosts: Permission denied`. The base image, i.e. [`node-red-docker`](https://github.com/node-red/node-red-docker/blob/master/latest/Dockerfile), changes the user to a non-root user without `sudo` privilege; so we have to try another way. – momocow May 04 '18 at 10:39
  • You may change npm configuration to tell it use the IP (151.101.52.162) instead of the domain name (registry.npmjs.org), (See [official npm doc](https://docs.npmjs.com/misc/config#registry)). The following workaround uses environment variable to change npm config (there's other ways mentioned in the official doc). Add this line before you call `npm install`: `ENV NPM_CONFIG_REGISTRY=https://151.101.52.162`. – momocow May 04 '18 at 10:53
  • @momocow,it was issue of DNS lookup. – Arshanvit May 04 '18 at 11:16

1 Answers1

2

As mentioned in comment by hardlib,it was actually the issue of DNS lookup and as per link,I was able to solve the same issue.Thus,reiterating those steps to avoid further confusion:

1)Find the DNS pertaining to your system:

nmcli device show <interface-name> | grep IP4.DNS

where interface-name is the name found by by ifconfig.

2)Edit the docker.service file kept in /lib/systemd/system and replacing the ExecStart line in following manner and save:

ExecStart=/usr/bin/dockerd --dns <dns-id> --dns <dns-id> -H fd://

where dns-id is the value found from above step.

3)Restart the service

sudo systemctl daemon-reload
sudo systemctl restart docker
Arshanvit
  • 417
  • 1
  • 7
  • 28