我目前正在尝试将Docker容器端口从容器映射到主机(boot2docker).最终的目标是将这些端口映射到我的物理机器,但是一次一个.
我的Vagrantfile目前看起来像:
Vagrant.configure("2") do |config|
config.vm.define "app1" do |a|
a.vm.provider "docker" do |d|
d.build_dir = "dockers/app1"
d.name = "app1"
d.ports << "8080:8080"
d.ports << "8443:8443"
d.volumes << "/vagrant/data/app1:/var/app1"
end
end
config.vm.define "app2" do |a|
a.vm.provider "docker" do |d|
d.build_dir = "dockers/app2"
d.name = "app2"
d.ports << "8081:8081"
d.link("app1:app1")
end
end
end
当我运行流氓app1 –provider = docker容器旋转正确,但是当我做一个docker ps我可以看到端口没有被映射.
0.0.0.0:2222->22/tcp,8080/tcp,8443/tcp
我正在使用VirtualBox,所以我已经使用它GUI将我的物理机8080转发到主机(boot2docker)8080.
最佳答案
您的配置应该在Linux上运行,但如果您使用的是VirtualBox(我假设您在Mac或Windows上),那么您需要为您的虚拟机提供一个Vagrantfile才能将其发送到您的主机.
原文链接:https://www.f2er.com/docker/436434.htmlVagrant.configure("2") do |config|
config.vm.Box = "busyBox"
config.vm.provider "virtualBox" do |v|
v.memory = 768
v.cpus = 2
end
config.vm.network :forwarded_port,guest: 8080,host: 8080
end
假设这是相对于您当前的Vagrantfile的host-vm / Vagrantfile.所以你目前的Vagrantfile应该是:
Vagrant.configure("2") do |config|
config.vm.define "app1" do |a|
a.vm.provider "docker" do |d|
d.vagrant_vagrantfile = "host-vm/Vagrantfile"
d.build_dir = "dockers/app1"
d.name = "app1"
d.ports = ["8080:8080"]
d.ports = ["8443:8443"]
d.create_args = ["-v","/vagrant/data/app1:/var/app1"]
end
end
config.vm.define "app2" do |a|
a.vm.provider "docker" do |d|
d.vagrant_vagrantfile = "host-vm/Vagrantfile"
d.build_dir = "dockers/app2"
d.name = "app2"
d.ports = ["8081:8081"]
d.link("app1:app1")
end
end
end