我的 Hapi 应用程序似乎正在 Docker 容器中运行,但我无法在浏览器中访问它。我以为docker run -d -p 8080:3000
本来会这么做的,但我想不会。我正在运行 boot to docker,但两者都没有http://localhost:8080/hello
nor http://192.168.99.100:8080/hello
工作中。
我也尝试过很多变体。
这是我跑步时看到的docker inspect <container id>
:
Server running at: http://localhost:8080
这是我的 Hapi.js 服务器:
'use strict';
const Hapi = require('hapi');
// Create a server with a host and port
const server = Hapi.server({
host: 'localhost',
port: 3000
});
// Add the route
server.route({
method: 'GET',
path:'/hello',
handler: function (request, h) {
return 'hello world';
}
});
async function start() {
try {
await server.start();
}
catch (err) {
console.log(err);
process.exit(1);
}
console.log(`App running at: ${server.info.uri}/hello`);
}
start();
这是我的 Dockerfile:
FROM node:8.9.3
MAINTAINER My Name <[email protected]>
ENV NODE_ENV=production
ENV PORT=3000
ENV user node
WORKDIR /var/www
COPY package.json yarn.lock ./
RUN cd /var/www && yarn
COPY . .
EXPOSE $PORT
ENTRYPOINT ["yarn", "start"]
这是我的 package.json:
{
"name": "my-app",
"version": "1.0.0",
"repository": "https://github.com/myname/myrepo.git",
"author": "My Name",
"license": "MIT",
"private": true,
"dependencies": {
"hapi": "17.2.0"
},
"scripts": {
"start": "node ./src/server"
}
}