雖然試圖dockerize節點的應用程序,當我訪問本地主機:8000我得到這個錯誤:當我使用run命令圖像Dockerizing的Node.js應用
The connection was reset - the connection to the server was reset while the page was loading.
在終端,我得到所需的輸出在控制檯中。它說:
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"
}
下面是我用
運行命令sudo docker run -p 8000:8000 -it --name node-container2 my-node-image
所有這些文件保存在同一個目錄中。
你如何運行容器? – Sergiu
sudo docker run -p 8000:8000 -it --name node-container2 my-node-image – Himansingh
通過編輯將其添加到問題中。 – Veve