Mac OS X上的Vagrant、Docker和Node.js

Mac OS X上的Vagrant、Docker和Node.js,node.js,macos,vagrant,docker,Node.js,Macos,Vagrant,Docker,我已经为此忙了一整天了,谢谢你的帮助。我在Mac OS X上运行Vagrant,我想运行一个Docker容器,里面运行一个简单的node.js“hello world”服务器。我希望能够从我的浏览器访问此服务器 这是我的Vagrantfile.proxy(用于运行docker服务器): 这是我的档案: # -*- mode: ruby -*- # vi: set ft=ruby : # Vagrantfile API/syntax version. Don't touch unless you

我已经为此忙了一整天了,谢谢你的帮助。我在Mac OS X上运行Vagrant,我想运行一个Docker容器,里面运行一个简单的node.js“hello world”服务器。我希望能够从我的浏览器访问此服务器

这是我的Vagrantfile.proxy(用于运行docker服务器):

这是我的档案:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # Tells vagrant to build the image based on the Dockerfile found in
  # the same directory as this Vagrantfile.
  config.vm.define "nodejs" do |v|
    v.vm.provider "docker" do |d|
      d.build_dir = "."
      d.ports = ['8888:8888']
      d.vagrant_vagrantfile = "./Vagrantfile.proxy"
    end
  end

  config.vm.network :forwarded_port, host: 8888, guest: 8888
end
这是我的Dockerfile:

FROM ubuntu:14.04
MAINTAINER Sean

RUN apt-get update
RUN apt-get install -y python-software-properties python
RUN echo "deb http://us.archive.ubuntu.com/ubuntu/ precise universe" >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y nodejs
RUN mkdir /var/www

ADD app.js /var/www/app.js

CMD ["/usr/bin/nodejs", "/var/www/app.js"]

EXPOSE 8888
下面是id app.js(node.js简单服务器):

我使用“vagrant up--provider=“docker”启动系统。然后我检查服务器是否开始使用“vagrant docker logs”,它显示控制台输出。然后我试着

'curl http://localhost:8888'
但每次我都会收到“curl:(52)服务器的空回复”


我遗漏了什么?

问题是我试图在127.0.0.1而不是0.0.0.0上运行nodejs服务器。经修订的完整资料来源可在以下网址找到:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8888, '127.0.0.1');
console.log('Server running at http://127.0.0.1:8888/');
'curl http://localhost:8888'