2015-01-16 20 views
10

Sto installando una semplice app node.js sulla piattaforma mobile di un server digitale dell'oceano.non è possibile installare npm nel contenitore docker?

// package.json

{ 
    "name": "docker-centos-hello", 
    "private": true, 
    "version": "0.0.1", 
    "description": "Node.js Hello world app on CentOS using docker", 
    "author": "Daniel Gasienica <[email protected]>", 
    "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); 

// finestra mobile di file

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

L'immagine di base finestra mobile è il dockerfile/nodejs, che ha costruito un node.js, ho costruito l'immagine:

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

ed eseguire l'immagine:

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

Eseguendo l'immagine, posso con successo nel contenitore, i file di app sono tutti copiati nel contenitore. quando ho provato il comando per installare la dipendenza node.js:

npm install 

Tuttavia, NPM non può scaricare tutti i pacchetti, con un errore:

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' 

risposta

16

Assicurarsi che il DNS sia impostato correttamente. Ho avuto alcuni problemi che erano andati dopo il riavvio del servizio docker. Se non ti è stato d'aiuto, potresti voler utilizzare l'interruttore del docker --dns 8.8.8.8.

Riavvio servizio finestra mobile:

  • sull'architettura systemd - sudo systemctl restart docker
  • boot2docker - boot2docker restart
  • Docker Machine - docker-machine restart <machine_name>

Inoltre, ho fatto qualcosa di simile (nodejs immagine), ma Ho usato un'altra immagine di base, sentiti libero di usare qualsiasi cosa ti serva dal mio repo.

+3

Grazie! Il riavvio della finestra mobile ('boot2docker restart') ha funzionato per me. – Leons

+3

Adattato per Docker Machine Suggerimento @Leons ha funzionato per me: 'docker-machine restart ' – marcusstenbeck

+0

Grazie, aggiornerò la risposta –

Problemi correlati