DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Auto Remediation of GuardDuty Findings for a Compromised ECS Cluster in AWSVPC Network Mode
  • Manage Microservices With Docker Compose
  • The Evolution of Scalable and Resilient Container Infrastructure
  • Scaling Microservices With Docker and Kubernetes on Production

Trending

  • Navigating Change Management: A Guide for Engineers
  • How to Introduce a New API Quickly Using Micronaut
  • Memory-Optimized Tables: Implementation Strategies for SQL Server
  • AI Speaks for the World... But Whose Humanity Does It Learn From?
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Docker Bridge and Overlay Network with Compose Variable Substitution

Docker Bridge and Overlay Network with Compose Variable Substitution

With Docker Multi-Host networking, you can create virtual networks and add containers. Bridge networks can cater to single host, while overlay networks are for multiple hosts. Learn about Docker bridge and overlay networks, and see what happens when a bridge or overlay already exists.

By 
Arun Gupta user avatar
Arun Gupta
·
Dec. 11, 15 · Analysis
Likes (3)
Comment
Save
Tweet
Share
18.7K Views

Join the DZone community and get the full member experience.

Join For Free

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:
    docker network create -d bridge mynet
    47d6225ffe56ddd1a8bc0d6abb0ffd8f8ac3eec2090ff243f8cd6f77c170751b=
  2. List the networks:
    docker network ls
    NETWORK ID          NAME                DRIVER
    feb6e9567439        bridge              bridge              
    29563a59abe8        none                null                
    25ab737cd665        host                host                
    47d6225ffe56        mynet               bridge
    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:
    [
        {
            "Name": "mynet",
            "Id": "47d6225ffe56ddd1a8bc0d6abb0ffd8f8ac3eec2090ff243f8cd6f77c170751b",
            "Scope": "local",
            "Driver": "bridge",
            "IPAM": {
                "Driver": "default",
                "Config": [
                    {}
                ]
            },
            "Containers": {},
            "Options": {}
        }
    ]
    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:
    mycouchbase:
      container_name: "db"
      image: couchbase/server
      ports:
        - 8091:8091
        - 8092:8092 
        - 8093:8093 
        - 11210:11210
      net: ${NETWORK}
    mywildfly:
      image: arungupta/wildfly-admin
      environment:
        - COUCHBASE_URI=db
      ports:
        - 8080:8080
        - 9990:9990
      net: ${NETWORK}
    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:
    NETWORK=mynet docker-compose up -d
  3. Inspect the network again:
    docker network inspect mynet
    [
        {
            "Name": "mynet",
            "Id": "47d6225ffe56ddd1a8bc0d6abb0ffd8f8ac3eec2090ff243f8cd6f77c170751b",
            "Scope": "local",
            "Driver": "bridge",
            "IPAM": {
                "Driver": "default",
                "Config": [
                    {}
                ]
            },
            "Containers": {
                "300bebe6c3e0350ebf9b9d3746eb3a7b49444e14c00314770627a9f101442639": {
                    "EndpointID": "82a3e2d7cd4f1bb03c9ef52bb6abf284942d7e9fcac89fe3700b0e0c4ed2654f",
                    "MacAddress": "02:42:ac:14:00:03",
                    "IPv4Address": "172.20.0.3/16",
                    "IPv6Address": ""
                },
                "4fdae4eb919f0934422513227fe541255557dd9e8b3317374685927e7f427249": {
                    "EndpointID": "937605d716d144b55288d70817d611da5fb0f87e3aedd6b5074fca07f82c3953",
                    "MacAddress": "02:42:ac:14:00:02",
                    "IPv4Address": "172.20.0.2/16",
                    "IPv6Address": ""
                }
            },
            "Options": {}
        }
    ]
    And now the two containers are assigned to this network as well.
  4. Check the container id using docker ps:
    CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS                                                                                               NAMES
    300bebe6c3e0        couchbase/server          "/entrypoint.sh couch"   2 minutes ago       Up 2 minutes        0.0.0.0:8091-8093->8091-8093/tcp, 11207/tcp, 11211/tcp, 0.0.0.0:11210->11210/tcp, 18091-18092/tcp   db
    4fdae4eb919f        arungupta/wildfly-admin   "/opt/jboss/wildfly/b"   2 minutes ago       Up 2 minutes        0.0.0.0:8080->8080/tcp, 0.0.0.0:9990->9990/tcp                                                      wildflycouchbasejavaee7network_mywildfly_1
  5. Check the network for one container:
    docker inspect -f '{{ .HostConfig.NetworkMode }}' 300
    mynet
  6. More details about the network:
    docker inspect -f '{{ .NetworkSettings.Networks.mynet }}' 300
    {82a3e2d7cd4f1bb03c9ef52bb6abf284942d7e9fcac89fe3700b0e0c4ed2654f 172.20.0.1 172.20.0.3 16   0 02:42:ac:14:00:03}
  7. More details about the container can be found using docker inspect, relevant portion is shown here:
    "Networks": {
        "mynet": {
            "EndpointID": "82a3e2d7cd4f1bb03c9ef52bb6abf284942d7e9fcac89fe3700b0e0c4ed2654f",
            "Gateway": "172.20.0.1",
            "IPAddress": "172.20.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "MacAddress": "02:42:ac:14:00:03"
        }
    }

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.

Docker (software) Network

Published at DZone with permission of Arun Gupta. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Auto Remediation of GuardDuty Findings for a Compromised ECS Cluster in AWSVPC Network Mode
  • Manage Microservices With Docker Compose
  • The Evolution of Scalable and Resilient Container Infrastructure
  • Scaling Microservices With Docker and Kubernetes on Production

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!