1
我一直在這裏對着牆壁敲打我的頭,因此感謝您的幫助。我在Mac OS X上運行Vagrant,我想用一個簡單的node.js'hello world'服務器運行Docker容器。我希望能夠從我的瀏覽器訪問此服務器。Mac OS X上的Vagrant,Docker和Node.js
這是我Vagrantfile.proxy(用於運行服務器泊塢窗):
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'
但我每次都得到'curl:(52)來自服務器的空回覆'。
我錯過了什麼?