代码之家  ›  专栏  ›  技术社区  ›  Arshanvit

VM上的docker内没有internet

  •  0
  • Arshanvit  · 技术社区  · 6 年前

    我正在使用docker compose以以下方式运行nodejs的模式红色模块:

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

    我已将以下docker文件放在文件夹中 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
    

    当我建立形象时 明确地 从这个docker文件中,按以下方式 好的

    docker build --network host -t dvnode .

    但当我使用docker compose时,会出现以下错误:

    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
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Arshanvit    6 年前

    正如hardlib在评论中提到的,这实际上是DNS查找的问题,根据 link ,我能够解决同样的问题。因此,重申这些步骤以避免进一步混淆:

    1) 查找与系统相关的DNS:

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

    其中,interface name是由找到的名称 ifconfig

    2) 编辑 docker.service 文件保存在 /lib/systemd/system 以及更换 ExecStart 按以下方式行并保存:

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

    哪里 dns-id 是从上述步骤中找到的值。

    3) 重新启动服务

    sudo systemctl daemon-reload
    sudo systemctl restart docker