Skip to main content

Vagrant Forwarding Ports Exposed by Docker

·1 min

Playing around with docker running inside a Vagrant VM and trying to use some services being exposed via HTTP ports makes you ask how to automatically forward the exposed docker ports through Vagrant to the host system. phew

I found an already merged pull request, which looked like what I wanted. So, after a peek into the docker Vagrant file I tried to expose a CouchDB port to the host system like this:

$host> FORWARD_DOCKER_PORTS='true' vagrant up
$host> vagrant ssh
$vagrant> docker run -d -p 49815:5984 -i -t gesellix/docker-example
$host> curl -X GET "http://localhost:49815"

It just worked! If you’d like to have a look at my example project, you can find it at GitHub. I’m going to continue building a complete application backend including CouchDB, ElasticSearch and other toys. You might have better docker or Vagrant knowledge than me, so if you’d have any hints, I’d really like some feedback. Thanks!