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);
})