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.
- Error while composing a docker image
- Docker run tomcat image without port mapping
- Golang: Is it safe to say that if a struct implements a method then it satisfies all interfaces that define that method's signature?
- Docker Private registry - access registry images after container is removed
- Docker installation issues on Windows 10 Home Edition
- SSH agent forwarding during docker build
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.