5

I have created two docker networks:

docker network create --driver=bridge --subnet=172.1.0.0/16 --ip-range=172.1.5.0/24 --gateway=172.1.5.254 br1


docker network create --driver=bridge --subnet=172.2.0.0/16 --ip-range=172.2.5.0/24 --gateway=172.2.5.254 br2

I am doing this in order to facilitate easier container interactions within that network (I do not need to expose ports for containers within that subnet).

Now however, I am interested in networking a few services between my two subnets within Docker (perhaps A as 172.1.0.0 and B as 172.2.0.0).

How can I expose a port so that they can connect to each other between the two subnets? Previous to making the docker subnet, I could just use -p 8000:8000 to expose ports when I ran docker images and then have access the required port.

I am using docker version 1.10.1 and docker-machine.


The documentation suggests this is possible but gives no real examples:

Within a user-defined bridge network, linking is not supported. You can expose and publish container ports on containers in this network. This is useful if you want to make a portion of the bridge network available to an outside network. enter image description here

4
  • Why can't you continue using -p? Feb 17, 2016 at 22:43
  • @PreferenceBean the connection no longer works (when using that configuration as above). I suspect it has to do with the reasons listed in the documentation, that they are intentionally isolated from each other when running in a subnet.
    – enderland
    Feb 17, 2016 at 22:44
  • Oh, right. Yeah, looks pretty clear. You'd have to bounce traffic off a node on the outside. Feb 17, 2016 at 22:48
  • Does this external_container is hosted in another network outside your container1-Docker_host-LAN? If so it is a NAT/PAT issue.
    – Auzias
    Feb 18, 2016 at 8:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.