diff --git a/CHANGELOG.md b/CHANGELOG.md index 34f0f83df..02674cb97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ BUG FIXES: - core: Fix cases where sometimes SSH connection would hang. - providers/docker: Create args works. [GH-4526] - providers/docker: Nicer error if package is called. [GH-4595] + - providers/docker: Host IP restriction is forwarded through. [GH-4505] + - providers/docker: Protocol is now honored in direct `ports settings. - providers/virtualbox: Show a human-friendly error if VirtualBox didn't clean up an existing VM. [GH-4681] - provisioners/docker: Search for docker binary in multiple places. [GH-4580] diff --git a/plugins/providers/docker/action/create.rb b/plugins/providers/docker/action/create.rb index e960f10b0..bf56906da 100644 --- a/plugins/providers/docker/action/create.rb +++ b/plugins/providers/docker/action/create.rb @@ -143,7 +143,9 @@ module VagrantPlugins result += mappings.values.map do |fp| protocol = "" protocol = "/udp" if fp[:protocol].to_s == "udp" - "#{fp[:host]}:#{fp[:guest]}#{protocol}" + host_ip = "" + host_ip = "#{fp[:host_ip]}:" if fp[:host_ip] + "#{host_ip}#{fp[:host]}:#{fp[:guest]}#{protocol}" end.compact result diff --git a/plugins/providers/docker/action/forwarded_ports.rb b/plugins/providers/docker/action/forwarded_ports.rb index db78c33ac..ed51b086d 100644 --- a/plugins/providers/docker/action/forwarded_ports.rb +++ b/plugins/providers/docker/action/forwarded_ports.rb @@ -8,9 +8,19 @@ module VagrantPlugins def call(env) env[:machine].provider_config.ports.each do |p| + host_ip = nil + protocol = "tcp" host, guest = p.split(":", 2) + if guest.include?(":") + host_ip = host + host, guest = guest.split(":", 2) + end + + guest, protocol = guest.split("/", 2) if guest.include?("/") env[:machine].config.vm.network "forwarded_port", - host: host.to_i, guest: guest.to_i + host: host.to_i, guest: guest.to_i, + host_ip: host_ip, + protocol: protocol end @app.call(env) diff --git a/plugins/providers/docker/config.rb b/plugins/providers/docker/config.rb index 097ecb0fa..a0a2421fc 100644 --- a/plugins/providers/docker/config.rb +++ b/plugins/providers/docker/config.rb @@ -96,7 +96,7 @@ module VagrantPlugins @image = UNSET_VALUE @name = UNSET_VALUE @links = [] - @ports = [] + @ports = UNSET_VALUE @privileged = UNSET_VALUE @remains_running = UNSET_VALUE @volumes = [] @@ -148,6 +148,7 @@ module VagrantPlugins @has_ssh = false if @has_ssh == UNSET_VALUE @image = nil if @image == UNSET_VALUE @name = nil if @name == UNSET_VALUE + @ports = [] if @ports == UNSET_VALUE @privileged = false if @privileged == UNSET_VALUE @remains_running = true if @remains_running == UNSET_VALUE @vagrant_machine = nil if @vagrant_machine == UNSET_VALUE