我有一個簡單的nginx,node.js設置,我想遷移到Vagrant,Docker世界。我不知道如何處理IP和端口。Mac OS X,Vagrant,Docker,Nginx,Node - 端口如何一起玩?
我的目標是在瀏覽器中看到我的Hello World
,在端口80上看到最好的情況,只需調用我的主機http://example.com
即可。
UPDATE 我找到了解決辦法我自己 - 我創建了一個簡單的樣板這裏: https://github.com/ezmilhouse/docker 隨意從這裏下去。
app.js
var app = express();
app.route('*').all(function(req, res) {
res.send('Hello World!');
});
app.listen(2000)
nginx.conf
upstream example.com {
# using the vagrant private network IP (I guess?)
# using the node port
server 192.168.33.10:2000
}
server {
# ports nginx server is listen to
listen 80;
listen 443;
location/{
# upstream proxy
proxy_pass http://example.com;
# ...
}
}
Vagrantfile.proxy
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provision "docker"
# settimg a hostname that matches nginx upstream (I guess?)
config.vm.hostname = "example.com"
# setting a private network IP, node.js and nginx run on this IP (i guess?)
config.vm.network "private_network", ip: "192.168.33.10"
end
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.define "nginx" do |app|
# forward the nginx port (I guess?)
app.vm.network "forwarded_port", guest: 80, host: 80
app.vm.provider "docker" do |d|
d.build_dir = "./docker/nginx"
d.vagrant_vagrantfile = "./Vagrantfile.proxy"
end
end
config.vm.define "node" do |app|
# forward the node port (I guess?)
app.vm.network "forwarded_port", guest: 2000, host: 2000
app.vm.provider "docker" do |d|
d.build_dir = "./docker/node"
d.vagrant_vagrantfile = "./Vagrantfile.proxy"
end
end
end
/nginx的/ Dockerfile
# ...
EXPOSE ["80"]
/節點/ Dockerfile
# ...
EXPOSE ["2000"]
的Mac OS X的/ etc /主機
192.168.33.10 example.com
我期待在瀏覽器中調用http://192.168.33.10
,通過nginx和http://192.168.33.10:2000
查看我的Hello World
以查看節點實例。因此主機example.com
也不起作用。
我該怎麼做?
找到你能儘量暴露部分n而非EXPOSE [ 「N」]? – seanmcl 2014-10-11 13:44:39
你能分享一個鏈接到你的代碼github回購?有趣的是玩一下 – kharandziuk 2014-10-11 16:31:34
@kharandziuk - github repo here:https://github.com/ezmilhouse/docker – ezmilhouse 2014-10-11 18:55:03