Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To establish a connection on a local network through Docker and Bridge, follow these steps:

  1. Create a bridge network in Docker using the following command:

    docker network create --driver bridge my-bridge-network

  2. Launch the container/s that will be part of the bridge network using the following command:

    docker run --name my-container --network my-bridge-network -d my-image:tag

  3. Check the IP addresses assigned to the containers in the bridge network using the following command:

    docker network inspect my-bridge-network

    This command will output a JSON object with information about the bridge network, including the IP addresses assigned to the containers.

  4. To test the connection between the containers, start a bash session in one of the containers using the following command:

    docker exec -ti my-container bash

  5. From within the container, ping the other container using its IP address.

    For example, if the IP address of the other container is 172.16.0.2, use the following command:

    ping 172.16.0.2

    If the ping is successful, it means that the two containers are connected on the same local network.

That's it - you have successfully established a connection between two Docker containers on a local network using a bridge network!