Using a Docker Bridge Network

Hands-On Lab

 

Photo of Will Boyd

Will Boyd

DevOps Team Lead in Content

Length

00:30:00

Difficulty

Intermediate

By default, all containers on a host can communicate with one another over a default bridge network. However, in some cases, you may want to isolate groups of containers by allowing them to communicate over their own isolated network. In this lab, you will have the opportunity to create a custom bridge network designed to facilitate communication between containers on a Docker host.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Using a Docker Bridge Network

Introduction

By default, all containers on a host can communicate with one another over a default bridge network. However, in some cases, you may want to isolate groups of containers by allowing them to communicate over their own isolated network.

In this lab, you will have the opportunity to create a custom bridge network designed to facilitate communication between containers on a Docker host.

Solution

  1. Begin by logging in to the lab server using the credentials provided on the hands-on lab page:

    ssh cloud_user@PUBLIC_IP_ADDRESS

Create the Bridge Network

  1. Create a bridge network called prices-net.

    docker network create --driver bridge prices-net

Create the base-price Container

  1. Create a container for the component that serves base prices.

    docker run --name base-price -d --network prices-net linuxacademycontent/prices-base-price:1

Create the sales Container

  1. Create a container for the component that serves products on sale.

    docker run --name sales -d --network prices-net linuxacademycontent/prices-sales:1

Create the total-price Container

  1. Create a container for the component that serves the total prices of products.

    docker run --name total-price -d --network prices-net -p 8080:80 linuxacademycontent/prices-total-price:1
  2. Verify that everything is set up correctly.

    curl localhost:8080

    You should get a list of products and their final prices. The total-prices container calculates these prices by first querying the other two containers. This communication takes place over the prices-net bridge network.

Conclusion

Congratulations — you've completed this hands-on lab!