실행중인 고정 표시기 컨테이너에 액세스 할 수 없습니다. 가장 최근 hello-world3은 8080 포트를 사용하는 노드 앱입니다. node.app를 통해 해당 포트에서 수신 대기하는 노드 앱을 보유하고 있습니다. 나는 PORT=8080
을 npm 시작 스크립트로 설정하고 나는 8080을 도커 파일로 설정했다. 컨테이너를 만든 후에 포트를 지정합니다. 이 경우 8082에 의해 docker run -p 8082:8080 hello-world3
Windows에서 도커 컨테이너에 액세스 할 수 없습니다. localhost
내 콘솔 에서이 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);
})