我一直在墙上撞了一整天,谢谢你的帮助。我在Mac OS X上运行Vagrant,我想运行一个带有简单node.js' hello world'的Docker容器。服务器在里面运行我希望能够从我的浏览器访问此服务器。
这是我的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
这是我的Vagrantfile:
# -*- 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'
但我得到了卷曲:(52)来自服务器的空回复'每一次。
我错过了什么?