1

How can I do the private networking for the boot2docker docker container ?

For example, If I have a webapp, I can do the following in Vagrantfile

  myapp1.vm.network "private_network", ip: "1.2.3.4"
  myapp2.vm.network "private_network", ip: "1.2.3.5"
  myapp3.vm.network "private_network", ip: "1.2.3.6"

Then I can use my browser to access my webapp at

http://1.2.3.4
http://1.2.3.5
http://1.2.3.6

How can I achieve the same result in docker easily ?

I also looked at How to expose docker container's ip and port to outside docker host without port mapping?

But in my boot2docker1.3, it said the interface eth0:1 does not exist

I looked at https://docs.docker.com/articles/networking

The tutorial does not work for boot2docker in mac.

Any help would be appreciated, thankyou!

Community
  • 1
  • 1
runcode
  • 3,533
  • 9
  • 35
  • 52
  • What do you want to do with this network? Do you want it to be private to just one container? Do you want multiple containers to be able to communicate over it? – Bryan Nov 04 '14 at 13:58
  • Thanks , for multiple container to talk with each other , i can link them together --link , i want each container have it's own ip , so I can access each of them externally (as web service) – runcode Nov 04 '14 at 15:52
  • They will all get a unique ip by default, but it will be randomly allocated by Docker and traffic won't route to it from off-box. You could use https://github.com/zettio/weave to address these points with the 'attach' and 'expose' features. (Note: I work for Zettio) – Bryan Nov 04 '14 at 19:41
  • but that docker container ip cant access from my host(mac browser), I can do some port mapping , to map it to host , but this is not what I want , I want each container(as webapp) to have a ip that I can access via the browser directly instead of using mapping to boot2docker host ip – runcode Nov 04 '14 at 19:43
  • Oh, you are using Boot2Docker on a Mac? That makes things more complicated, since there are two hosts - the Mac and the VirtualBox VM. – Bryan Nov 04 '14 at 19:52
  • I updated the question, I think this is more like a routing or NAT setting problem. I dont know ,I just need some guides, I dont have much on setting up networking stuffs – runcode Nov 04 '14 at 19:55

1 Answers1

3

I believe the instructions here, linked from this question give what you are looking for. The key is this line:

sudo route -n add 172.17.0.0/16 172.16.0.11

which tells your Mac how to route to the private network inside the VirtualBox VM that the Docker containers are on. (Obviously the specific addresses can change for your specific situation)

This still doesn't give you the ability to assign specific IP addresses to specific containers; as I said an add-on like weave can do that. (note: I work on weave)

You may also like this article which gives a beginner's overview of how Boot2Docker runs and illustrates how you have IP addresses inside the VirtualBox VM, and also an IP address of that box as a whole.

Community
  • 1
  • 1
Bryan
  • 11,398
  • 3
  • 53
  • 78