Node.js 节点Docker运行,但可以';我看不到申请表

Node.js 节点Docker运行,但可以';我看不到申请表,node.js,docker,hapijs,Node.js,Docker,Hapijs,看起来我的Hapi应用程序正在Docker容器中运行,但我无法在浏览器中点击它。我原以为docker run-d-p8080:3000能做到,但我想不行。我正在运行boot to docker,两个都不是http://localhost:8080/hellonorhttp://192.168.99.100:8080/hello正在工作 我也试过很多不同的方法 这是我运行docker inspect时看到的: 这是我的Hapi.js服务器: 'use strict'; const Hapi =

看起来我的Hapi应用程序正在Docker容器中运行,但我无法在浏览器中点击它。我原以为docker run-d-p8080:3000能做到,但我想不行。我正在运行boot to docker,两个都不是
http://localhost:8080/hello
nor
http://192.168.99.100:8080/hello
正在工作

我也试过很多不同的方法

这是我运行docker inspect时看到的:

这是我的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@email.com>

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"]

问题不在于Docker,而在于如何配置节点服务器

如果绑定到
localhost
,则只能从docker容器中使用。如果要允许来自docker主机的连接,请不要提供主机名或使用
0.0.0.0

const server = Hapi.server({
    host: '0.0.0.0',
    port: 3000
});
{
    "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"
    }
}
const server = Hapi.server({
    host: '0.0.0.0',
    port: 3000
});