Tout en essayant de dockerize application de noeud, quand je visite localhost: 8000 je reçois cette erreur:Dockerizing Node.js application
The connection was reset - the connection to the server was reset while the page was loading.
Dans le terminal lorsque j'utilise la commande d'exécution sur l'image, je reçois la sortie désirée dans la console. Il dit:
Server running at http://localhost:8000/
Dockerfile:
FROM node
RUN mkdir -p /app/
WORKDIR /app
COPY package.json /app
RUN cd /app
RUN npm install
COPY . /app
CMD ["node", "index.js"]
EXPOSE 8000
index.js:
#!/usr/bin/env nodejs
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(8000, 'localhost');
console.log('Server running at http://localhost:8000/');
package.json:
{
"name": "server1",
"version": "1.0.0",
"description": "Dockerizing node-app",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Himanshu",
"license": "ISC"
}
Voici la commande d'exécution que je
sudo docker run -p 8000:8000 -it --name node-container2 my-node-image
Tous ces fichiers sont sauvegardés dans le même répertoire.
Comment lancez-vous le conteneur? – Sergiu
sudo docker run -p 8000: 8000 -it --nom noeud-conteneur2 mon-noeud-image – Himansingh
Ajouter ceci à la question en l'éditant. – Veve