Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Do you want multiple Docker containers to be able to communicate? You need to add the containers to the same docker network and this guide explains several ways to do that.

If you start and manage containers with Docker compose and YAML file, Docker compose creates the network and automatically links all the containers to the network. However, you can use existing networks in Compose as well.

Step 1: Create a Docker Network (Optional)

Creating a new Docker network is pretty simple. All you require is a single command – docker network create <network-name>.

In the example command below, I will create a bridge network called “mysql-phpadmin-nw.”

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker network create mysql-phpadmin-nw

The command creates the network and displays it ID. To confirm that the network has been created, I’ll run the “docker network ls” command.

Popular on Amazon
Amazon Basics RJ45 Cat 6 Ethernet Patch Internet Network Cable, 10Gbps High-Speed, 250MHz, Snagless, Gold-Plated Connectors, 15 Foot, Black
  • Cat-6 UTP (Unshield Twisted Pair) ethernet cables for connecting networked devices such as computers, printers, routers, and more
  • RJ45 connectors ensure universal connectivity; 250 MHz bandwidth
  • Low signal loss with a transmission speed up to 10 gigabit per second
  • Snagless plug design helps prevent damage when plugging/unplugging cable
  • Gold-plated contacts and bare copper conductors improve signal integrity and resist corrosion

How to Create a Docker Network

Finally, to confirm that no container is currently connected to this network, I’ll execute the command below:

Docker network inspect mysql-phpadmin-nw

The command returns a bunch of information about the network. Scrolling down to the “Containers” section, you’ll notice that it is currently empty.

This confirms that no container is connected to this network.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Docker network inspect

Step 2 (Option 1): Attach an Existing Container to a Network

You can join a running container to a network with a very simple Docker command. I have a running MySQL container that is not linked to the “mysql-phpadmin-nw” Docker network I created in the last section.

Also popular on Amazon
Sale
DbillionDa Cat 8 Ethernet Cable, 6FT 40Gbps 2000MHz RJ45 LAN Cable | 3FT 6FT 10FT 15FT 20FT 25FT 30FT 35FT 40FT 50FT 60FT 65FT 100FT 150FT Internet Cable for Router, Modem, Switch, PS5, Xbox
  • Designed for Outdoor & Direct Burial Installations – Heavy-duty double-shielded Cat8 Ethernet cable minimizes EMI/RFI interference and delivers stable long-distance performance. Waterproof, anti-corrosion PVC jacket allows safe direct burial and reliable use in outdoor or indoor environments.
  • 26AWG for Stable High-Load Networks – Thicker 26AWG conductors provide faster, more stable data transmission than standard 32AWG cables. Ideal for high-performance home networks, gaming setups, smart homes, and data-intensive applications.
  • F/FTP Shielding & Hyper-Speed Performance: Cat8 Ethernet cable constructed with 4 shielded foiled twisted pairs and 26AWG OFC conductors; supports bandwidth up to 2000 MHz and data transmission speeds up to 40 Gbps, effectively reducing signal interference and ensuring stable connections. Ideal for low-latency gaming, 4K/8K streaming, and high-speed internet connections.
  • RJ45 Connectors & Wide Compatibility: Cat8 Ethernet cable with two shielded RJ45 connectors; compatible with networking switches, IP cameras, routers, Nintendo Switch, modems, PS3, PS4, Xbox, patch panels, servers, smart TVs, and more; works with Cat7, Cat6, Cat5e, and Cat5 devices
  • Weatherproof & UV Resistant: Outdoor-rated Cat8 Ethernet cable with UV-resistant PVC jacket; withstands direct sunlight, extreme cold, humidity, and hot weather; anti-aging and durable; Includes 18-month support.

To bind the MySQL container to mysql-phpadmin-nw, I will execute the command below:

Docker network connect mysql-phpadmin-nw mysql

“mysql” is the name of the MySQL container. You can get this information by running the “docker ps” command.

Connect an Existing Container to a Network

Before proceeding, let’s check that the MySQL container is now linked to the mysql-phpadmin-nw network.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This time, the “Docker network inspect mysql-phpadmin-nw” command confirms that a container called “mysql” is connected to this network!

Also popular on Amazon
Sale
UGREEN Cat 8 Ethernet Cable 6FT, High Speed Braided 40Gbps 2000Mhz Network Cord Cat8 RJ45 Shielded Indoor Heavy Duty LAN Cables Compatible with Gaming PC PS5 PS4 PS3 Xbox Modem Router 6FT
  • 40 Gbps 2000 Mhz High Speed: The Cat 8 ethernet cable support max. 40 Gbps data transfer and 2000 MHz Brandwith, ideal for gaming and streaming, greatly improving upload and download speed, sound, image and resolution quality
  • Excellent Anti-interference: The ethernet cable comes with 4 shielded foiled twisted pairs (F/FTP), pure copper core and gold-plated RJ45 connector, reducing interference, noise and crosstalk, making network speed faster and more stable
  • Marvelous Durability: Internet cable wrapped with quality cotton braided cord, which makes the LAN cable stronger and more durable. The test proves that this internet cable can be bent at least 10000 times without broken, very suitable for long-term use
  • PoE Supported: All lengths of ethernet cord can support the PoE power supply function except 65ft. You don't need additional power supply when installing a PoE camera, which is very convenient and safe
  • Wide Compatibility: With the RJ45 Connector, network cable can be perfectly compatible with computers, laptops, modems, routers, PS5, X-Box and other networking devices. It can also be fully backward compatible with Cat7, Cat6e, Cat6, Cat5e, Cat5

Step 2 (Option 2): Join a Container to a Network at Creation

While starting a container with the “Docker run” command, you can attach a network to the container. To demonstrate this, I’ll start a phpmyadmin container and bind it to the network I created earlier.

A phpmyadmin container needs to connect to a running MySQL or MariaDB server in Docker. As I mentioned earlier, I have an existing MySQL container that is I connected to the mysql-phpadmin-nw Docker network.

I will now start a new phpmyadmin container and join it to the mysql-phpadmin-nw Docker network. Here is the command that performs this magic!

docker run -p 8081:80 \
--network mysql-phpadmin-nw \
--name phpmyadmin \
--link mysql:db \
-d phpmyadmin

The “–network” option is used to bind the new container to an existing network. Equally important to a phpmyadmin specifically is the “–link” option which is required to link it to the MySQL databases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Let’s now execute the command. Because I used the “-d” option, the container starts in detached mode.

Also popular on Amazon
Sale
Jadaol Cat6/Cat6A Ethernet Cable 50FT Flat with Clips 10Gbps Network, White | 1FT 3FT 5FT 10FT 15FT 20FT 25FT 30FT 35FT 50FT 60FT 75FT 100FT 150FT 200FT LAN Patch Cable for Router, Modem, Switch, Gaming
  • Cat 6 performance at a Cat5e price but with higher bandwidth
  • High Performance Cat6, 30 AWG, RJ45 Ethernet Patch Cable provides universal connectivity for LAN network components such as PCs,computer servers,printers,routers,switch boxes,network media players,NAS,VoIP phones
  • Jadaol cat6 standard cable support Cat8 and Cat7 network and provides performance of up to 250 MHz 10Gbps and is suitable for 10BASE-T, 100BASE-TX (Fast Ethernet), 1000BASE-T/1000BASE-TX (Gigabit Ethernet) and 10GBASE-T (10-Gigabit Ethernet)
  • UTP(Unshielded Twisted Pair) patch cable with RJ45 gold-plated Connectors and are made of 100% bare copper wire, ensure minimal noise and interference
  • The unique flat cable shape allows for a cleaner and safer installation. You can easily and seamlessly make the cable run along walls, follow edges & corners or even make it completely invisible by sliding it under a carpet.

This means that it starts on the background.

Once again, we’ll confirm that this newly started container is also linked to the network. Running the “Docker network inspect” command reveals that both containers are indeed connected to our Docker network!

Join a Container to a Network at Start-up
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

1. How do I move a Docker Container to another network?

Run the “docker network disconnect” command to detach the container from the existing network. After that, execute the “docker network connect” command to link the container to the new network.

2. Can a Docker Container be on two networks?

Yes, you can connect a Docker container to two networks.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
3. How to create a Docker network Bridge?

You can create a Docker network bridge by running the “Docker network create” command and entering the name of the bridged network you want to create at the end of the command.

For example to create a Docker network bridge called “test-bridge-network,” run this command: Docker network create test-bridge-network.

Also popular on Amazon
Amazon Basics RJ45 Cat-6 Ethernet Patch Internet Cable, 1Gbps Transfer Speed, Gold-Plated Connectors, 50 Foot, for PC, TV, Tablet, Router, Printer, Black
  • IN THE BOX: 50-foot RJ45 Cat-6 Ethernet patch internet cable
  • COMPATIBILITY: RJ45 connectors ensure universal connectivity
  • PERFORMANCE: Transmits data at speeds up to 1,000 Mbps (or 1 Gigabit per second); 10x faster than Cat-5 cables (100 Mbps)
  • USES: Connects computers to network components in a wired Local Area Network (LAN); great for laptops, tablets, routers, printers, gaming consoles, and more
  • DURABLE DESIGN: Gold plated RJ45 connectors for accurate data transfer and corrosion-free connectivity
4. Do Docker Containers have their own IP?

Yes, each Docker container has its IP address. You can view the IP address of a container by running the “docker container inspect” command.

The IP address of the container will be displayed in the “Networks” section of the results.

5. What is the default network in Docker?

The default Docker network driver is bridge.

Thank you for reading. Kindly share your thoughts about this topic or ask a question using the comments form at the bottom of this page.

Alternatively, you can respond to the “Was this page helpful?” question below.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.