A Docker bridge network is a virtual network that enables communication between Docker containers running on the same Docker host. By default, when you create a container, Docker connects it to the default bridge network called "bridge."
The bridge network acts as a software-based switch that connects multiple containers together. The bridge network also provides them with network connectivity. Each container connected to the bridge network gets its own IP address, and can communicate with other containers on the same network using these IP addresses.
To create a bridge network in Docker, you can use the Docker CLI. Here’s how you can create a bridge network using the Docker CLI:
Connect the terminal given at the end.
Run the following command to create a new bridge network:
docker network create --driver bridge my-bridge-network
Replace the my-bridge-network
with the desired name for your bridge network.
Verify that the bridge network has been created by running:
docker network ls
This command will list all the networks on your Docker host, and you should see our newly created bridge network in the list.
Once you have created the bridge network, you can start attaching containers to it. You can use the following command to connect new containers to your bridge network:
docker network connect my-bridge-network container_name
Replace the my-bridge-network
with the name of your bridge network and container_name
with the name or ID of the running container.
To inspect a Docker network, run the following command to display detailed information about the containers:
docker network inspect my-bridge-network
This command will provide detailed information about the specified network, including its configuration, connected containers, IP address ranges, and more.
That concludes the process of creating a bridge network in Docker and attaching containers to it, using the Docker CLI.
Note: By clicking the "Run" button, the execution will initiate, and create a new bridge network named
my-bridge-network
. A Redis container, named themy-redis-container
, will then be run and connected to this bridge. Alternatively, you can follow the above commands to manually create a new bridge network, and connect containers to your bridge network using the Docker CLI.
Free Resources