0
我似乎無法訪問我的任何運行的碼頭容器。最近的hello-world3是一個使用端口8080的節點應用程序。我有節點應用程序通過process.env.PORT在該端口上偵聽。我使用npm start腳本設置PORT=8080
,並使用docker文件EXPOSE 8080。在構建容器之後,我指定了一個端口。在這種情況下8082通過docker run -p 8082:8080 hello-world3
無法通過Windows本地主機訪問碼頭容器
從我的控制檯看這img我應該能夠看到我的應用程序響應通過轉到localhost:8082是啊?
我的搬運工文件
FROM jkilbride/node-npm-alpine:8
WORKDIR /src
COPY package.json .
RUN npm install
COPY . .
EXPOSE 8080
CMD ["npm","start"]
的package.json:
{
"name": "service",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start":"set PORT=8080 && node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
index.js:
const http = require('http');
const server = http.createServer((req,res) => {
const data = {
'data': 'Hello World',
'hostname': require('os').hostname()
};
res.writeHead(200, {'Content-Type': 'application/json'})
res.end(JSON.stringify(data));
});
server.listen(process.env.PORT, (err) => {
if (err)
return console.log(err);
console.log('API is running on ' + process.env.PORT);
})