can't install npm in the docker container?

I am deploying a simple node.js app on a digital ocean server ‘s docker platform.

// package.json

  • Distcc in docker causing memory leaks
  • Docker hello-world on Ubuntu - permission denied
  • Docker Exposing ports for Flask API
  • How to test dockerignore file?
  • Nginx conf wont work
  • Docker intermittently failing to start container
  • {
      "name": "docker-centos-hello",
      "private": true,
      "version": "0.0.1",
      "description": "Node.js Hello world app on CentOS using docker",
      "author": "Daniel Gasienica <daniel@gasienica.ch>",
      "dependencies": {
        "express": "3.2.4"
      }
    }
    

    // app.js

    var express = require('express');
    var PORT = 3000;
    var app = express();
    app.get('/', function (req, res) {
      res.send('Hello world\n');
    });  
    app.listen(PORT);
    console.log('Running on http://localhost:' + PORT);
    

    // docker file

    FROM dockerfile/nodejs
    # Set the working directory
    WORKDIR   /src
    EXPOSE  3000
    CMD ["/bin/bash"]
    

    The docker base image is the dockerfile/nodejs, which has built a node.js, I built the image:

    docker build -t test1 /home/sizhe/docker/test
    

    and run the image:

    docker run -it -p 8080:3000 -v /home/sizhe/docker/test1:/src test
    

    By running the image, I can successfully into the container, the app files are all copied into the container. when I tried the command to install the node.js dependency:

    npm install
    

    However, npm can’t download all the packages, with a error:

    Linux 3.13.0-40-generic
    npm ERR! argv "node" "/usr/local/bin/npm" "install"
    npm ERR! node v0.10.35
    npm ERR! npm  v2.1.16
    npm ERR! code ENOTFOUND
    npm ERR! errno ENOTFOUND
    npm ERR! syscall getaddrinfo
    
    npm ERR! network getaddrinfo ENOTFOUND
    npm ERR! network This is most likely not a problem with npm itself
    npm ERR! network and is related to network connectivity.
    npm ERR! network In most cases you are behind a proxy or have bad network settings.
    npm ERR! network 
    npm ERR! network If you are behind a proxy, please make sure that the
    npm ERR! network 'proxy' config is set properly.  See: 'npm help config'
    

  • Chef Test Kitchen verify file exists inside Docker container
  • ImageMagick Go API HTTP Hangs on ReadImageBlob
  • Use PredictionIO in production
  • Kafka and Docker: Pushing a Kafka Messages to the another's Dockerized Consumer
  • Sharing a single file from host machine with Docker Container and having the Container r+w to same file
  • symfony classes.map failed to open stream: No such file or directory
  • One Solution collect form web for “can't install npm in the docker container?”

    Make sure the dns is set properly. I had some issues that were gone after the docker service restart. If it didn’t help you may want to use the --dns 8.8.8.8 docker switch.

    Restarting docker service:

    • on systemd architecture – sudo systemctl restart docker
    • boot2docker – boot2docker restart
    • Docker Machine – docker-machine restart <machine_name>

    Also, I did something similar (nodejs image), but I’ve used another base image, feel free to use whatever you need from my repo.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.