Vagrant,Docker和Node.js在Mac OS X上

我已经把头撞在墙上整整一天了,所以谢谢你的帮助。 我在Mac OS X上运行Vagrant,我想运行一个Docker容器,里面运行着一个简单的node.js'hello world'服务器。 我希望能够从我的浏览器访问这个服务器。

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

VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "hashicorp/precise64" config.vm.provision "docker" config.vm.provision "shell", inline: "ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill" config.vm.network :forwarded_port, guest: 8888, host: 8888 end 

这是我的stream浪文件:

 # -*- 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简单的服务器):

 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/'); 

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

 'curl http://localhost:8888' 

但是我每次都得到'curl:(52)服务器空回复'。

我错过了什么?

问题是我试图在127.0.0.1上运行nodejs服务器,而不是0.0.0.0。 完整的修订来源可以在这里find。