Docker Bridge and Overlay Network with Compose Variable Substitution

Docker Multi-Host networking allows you to create virtual networks and attach containers to them so you can create the network topology that is right for your application. Bridge networks can be created for single host and overlay networks can be created for multiple hosts. Creating application-specific networks provides complete isolation for containers.

Docker Compose file can be targeted at a single host, and --x-networking will create a bridge network exclusive for the application. If the sample application is targeted at multiple hosts, say using Docker Swarm cluster, then an overlay network is created. Single host networking and multi host networking provide more details on how to set this up.

What if a bridge or an overlay network already exists and you’d like to assign this to your application started using Docker Compose?

Docker Networking

Docker 1.9 introduced variable substitution, and we can use that feature to target an application to a pre-created network.

Create New Docker Bridge Network

  1. Create a new network:
  2. List the networks:
    Docker create three networks for each host automatically:

    NETWORK NAME PURPOSE
    bridge Default network that containers connect to. This is docker0 network in all Docker installations.
    none Container-specific networking stack
    host Adds a container on hosts networking stack. Network configuration is identical to the host.

    In addition, you also see mynet network that was just created.

  3. Inspect the newly created network using docker network inspect mynet:

    No containers are assigned to it yet.

Docker Compose and Networking

  1. This new network can be used for any new container using docker run --net=<NETWORK> command. This blog will show how to target this network to a Compose file:

    Note how net is specified here to use a custom network. This Compose file is at: github.com/arun-gupta/docker-images/blob/master/wildfly-couchbase-javaee7-network/docker-compose.yml.

  2. Start the application, using our newly created network, as:

  3. Inspect the network again:

    And now the two containers are assigned to this network as well.

  4. Check the container id using docker ps:

  5. Check the network for one container:

  6. More details about the network:

  7. More details about the container can be found using docker inspect, relevant portion is shown here:

Create New Docker Overlay Network

Creating a new Docker overlay network requires to setup a key/value service and a Docker Swarm cluster. Multi-host and multi-container blog provide more details on that.

More details at Docker Networks.

Be Sociable, Share!
  • Tweet

4 thoughts on “Docker Bridge and Overlay Network with Compose Variable Substitution

  1. Please if you could kindly do a blog series on docker multi node networks and their security best practices.

    Best Regards
    Hareem Haque

  2. Pingback: 22-12-2015 - pre x-mas links from the greater internet and beyond - Magnus Udbjørg
  3. Hi, I have a problem with docker-compose in swarm cluster. Here is the issue:
    https://github.com/docker/compose/issues/4233

  4. As for me, it will be useful to read more about professional essay writers. On https://pro-essay-writer.com/blog/a-few-things-about-professional-essay-writers you can find such information

Leave a Reply

Your email address will not be published. Required fields are marked *