From 09cc823065dba028e2df16544510f7075304424a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 17 Apr 2014 15:35:04 -0700 Subject: [PATCH] providers/docker: warning with host VM about forwarded ports --- plugins/providers/docker/action.rb | 2 + .../action/host_machine_port_warning.rb | 37 +++++++++++++++++++ templates/locales/providers_docker.yml | 6 +++ 3 files changed, 45 insertions(+) create mode 100644 plugins/providers/docker/action/host_machine_port_warning.rb diff --git a/plugins/providers/docker/action.rb b/plugins/providers/docker/action.rb index f95c015b9..773836e96 100644 --- a/plugins/providers/docker/action.rb +++ b/plugins/providers/docker/action.rb @@ -27,6 +27,7 @@ module VagrantPlugins end end + b2.use HostMachinePortWarning b2.use HostMachinePortChecker b2.use HandleForwardedPortCollisions b2.use PrepareNFSValidIds @@ -220,6 +221,7 @@ module VagrantPlugins autoload :HasSSH, action_root.join("has_ssh") autoload :HostMachine, action_root.join("host_machine") autoload :HostMachinePortChecker, action_root.join("host_machine_port_checker") + autoload :HostMachinePortWarning, action_root.join("host_machine_port_warning") autoload :HostMachineRequired, action_root.join("host_machine_required") autoload :HostMachineSyncFolders, action_root.join("host_machine_sync_folders") autoload :HostMachineSyncFoldersDisable, action_root.join("host_machine_sync_folders_disable") diff --git a/plugins/providers/docker/action/host_machine_port_warning.rb b/plugins/providers/docker/action/host_machine_port_warning.rb new file mode 100644 index 000000000..13ad72636 --- /dev/null +++ b/plugins/providers/docker/action/host_machine_port_warning.rb @@ -0,0 +1,37 @@ +module VagrantPlugins + module DockerProvider + module Action + class HostMachinePortWarning + def initialize(app, env) + @app = app + end + + def call(env) + if !env[:machine].provider.host_vm? + return @app.call(env) + end + + # If we have forwarded ports, then notify the user that they + # won't be immediately available unless a private network + # is created. + if has_forwarded_ports?(env[:machine]) + env[:machine].ui.warn(I18n.t( + "docker_provider.host_machine_forwarded_ports")) + end + + @app.call(env) + end + + protected + + def has_forwarded_ports?(machine) + machine.config.vm.networks.each do |type, _| + return true if type == :forwarded_port + end + + false + end + end + end + end +end diff --git a/templates/locales/providers_docker.yml b/templates/locales/providers_docker.yml index 7e5eb8295..48fc0a14d 100644 --- a/templates/locales/providers_docker.yml +++ b/templates/locales/providers_docker.yml @@ -6,6 +6,12 @@ en: Container created: %{id} host_machine_disabling_folders: |- Removing synced folders... + host_machine_forwarded_ports: |- + Warning: When using a remote Docker host, forwarded ports will NOT be + immediately available on your machine. They will still be forwarded on + the remote machine, however, so if you have a way to access the remote + machine, then you should be able to access those ports there. This is + not an error, it is only an informational message. host_machine_needed: |- Docker host is required. One will be created if necessary... host_machine_ready: |-