Multiple docker containers, IP addresses, VM, OSX
I create several images of a web server. Docker assigns different IP address to each container, like
172.17.0.61. Each web server is running on port 8080.
- How to add module to Wildfly using CLI
- Expose container on random port on internal IP
- How can I find out which capabilities a container has been given?
- How do we set docker containers to restart on reboot and on-failure?
- Access web server over https in a Docker container
- What work does the process in container “gcr.io/google_containers/pause:0.8.0” do?
Inside VM, I can ping the server on this address.
How can I map these different container IP addresses (from VM) to the same one in VM, but on different port? E.G.
<local.ip>:9001 -> 172.17.0.61:8080 <local.ip>:9002 -> 172.17.0.62:8080
local.ip may be either ip from
boot2docker or anything else.
Possible solution is to define port bindings when creating container and bind each container to a different port. However, I would like to avoid that, since this config becomes part of the container, and only exist because running on OSX. If I do all this above on linux, we would not have this issue.
How to map inner containers to different ports?
One Solution collect form web for “Multiple docker containers, IP addresses, VM, OSX”
Publishing ports is the right solution. You have the same problem whether you’re running remotely or locally, just the IP address changes.
For example, say I start the following web servers:
$ docker run -d -p 8000:80 nginx $ docker run -d -p 8001:80 nginx
From inside the VM (run
boot2docker ssh), I can then run
curl localhost:8000 or
curl localhost:8001 to reach the website. This is the normal way of working with Docker on Linux. From the Mac command line, it becomes
curl $(boot2docker ip):8000 because of the VM, but we’ve not done anything different with regards to starting the web servers because of boot2docker.