mitchellh / boot2docker-vagrant-box

Packer scripts to build a Vagrant-compatible boot2docker box.
425 stars 183 forks source link

Forward container ports to the host #51

Open unwiredbrain opened 10 years ago

unwiredbrain commented 10 years ago

Please, add the ability to automatically forward the exposed ports to the host.

Let's say I'm using dockerfile/elasticsearch. Its Dockerfile exposes ports 9200 and 9300.

Here's the Vagrantfile I'm using:

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.define "elasticsearch" do |es|
    es.vm.provider "docker" do |container|
      container.image = "dockerfile/elasticsearch"
      container.ports = [ "9200:9200", "9300:9300" ]
      container.remains_running = true
    end
  end
end

On the boot2docker guest everything is fine

docker@boot2docker:~$ curl -sS -X GET http://127.0.0.1:9200/
{
  "status" : 200,
  "name" : "Sleepwalker",
  "version" : {
    "number" : "1.1.1",
    "build_hash" : "f1585f096d3f3985e73456debdc1a0745f512bbc",
    "build_timestamp" : "2014-04-16T14:27:12Z",
    "build_snapshot" : false,
    "lucene_version" : "4.7"
  },
  "tagline" : "You Know, for Search"
}

But no port is forwarded to the host

$ vagrant up elasticsearch --provider=docker
Bringing machine 'elasticsearch' up with 'docker' provider...
==> elasticsearch: Docker host is required. One will be created if necessary...
    elasticsearch: Docker host VM is already ready.
==> elasticsearch: Syncing folders to the host VM...
    elasticsearch: Rsyncing folder: <snip>/elasticsearch-docker/ => /var/lib/docker/docker_1401201151_90455
==> elasticsearch: Warning: When using a remote Docker host, forwarded ports will NOT be
==> elasticsearch: immediately available on your machine. They will still be forwarded on
==> elasticsearch: the remote machine, however, so if you have a way to access the remote
==> elasticsearch: machine, then you should be able to access those ports there. This is
==> elasticsearch: not an error, it is only an informational message.
==> elasticsearch: Creating the container...
    elasticsearch:   Name: elasticsearch-docker_elasticsearch_1401201153
    elasticsearch:  Image: dockerfile/elasticsearch
    elasticsearch: Volume: /var/lib/docker/docker_1401201151_90455:/vagrant
    elasticsearch:   Port: 2222:22
    elasticsearch:   Port: 9200:9200
    elasticsearch:   Port: 9300:9300
    elasticsearch:
    elasticsearch: Container created: ba322db5bdfe082a
==> elasticsearch: Starting container...
==> elasticsearch: Provisioners will not be run since container doesn't support SSH.

massimo@host ~/elasticsearch-docker $ curl -sS -X GET http://127.0.0.1:9200/
curl: (7) Failed connect to 127.0.0.1:9200; No error

Am I missing something?

unwiredbrain commented 10 years ago

Forgot to mention:


I also tried setting up a host-only interface and use that instead, but still no luck

config.vm.network "private_network", ip: "10.0.0.10"
$ curl -sS -X GET http://10.0.0.10:9200/
curl: (7) Failed connect to 10.0.0.10:9200; No error
adambiggs commented 10 years ago

I'm also experiencing this problem...