Docker Virtual Networking

Manfred Lange
11 min readApr 15, 2023

A gentle introduction to virtual networks with docker compose files


In my previous article “Docker Port Mapping” I explained what port mapping is and demonstrated how to use it. Using a browser, we were able to send a request deliberately to one of two running containers.

In this article, we will expand on the concept and figure out how running containers can communicate with each other. We will cover:

  • How to configure a virtual network with Docker?
  • How to send a request from one running container to a different container?

Understanding virtual networks in Docker is an important building block for more advanced setups. Examples of these advanced scenarios are provided in this article’s summary.

The complete source code for this article is available at

Why do we need a Virtual Network?

Last time, we ran up two different instances of the same container image. For each we configured a different port mapping so that depending on what we used in a browser we would make a request to either one or the other instance. Let us take a simple example.