# BRIDGE Networking in Docker

In 
Published 2022-12-03

This tutorial explains bridge networking mode in Docker.

Here is the picture which shows how bridge networking is working:

Here are the main things to retain:

  • This is the default network type (If you don’t specify a driver, this is the type of network you are creating).

  • Bridge networks are usually used when your applications run in standalone containers that need to communicate. Docker secures the network by managing rules that block connectivity between different Docker networks.

  • This type of containers are created with --network bridge option.

  • It is created from the bridge driver. A driver is like a template for the network with specific behavior and capability.

  • One container could be connected to more than one bridged network.

  • In order to have access to a service on a container we need to map the container port to a host port. This is done by using --publish or -p flag. More information you can get at IPs, Hostnames, Ports in Docker Containers.

  • You can start a Docker container in host networking mode as in the following example:

linux
docker run -d --network bridge -p 8080:80 httpd:latest

If you want to get more information about the default bridge network you can run the following command:

linux
docker network inspect bridge

The result will be something like this:

linux
[
    {
        "Name": "bridge",
        "Id": "db8e765f1473e70d3949aef0427c5acc5753eb462edbdcfabd044ea3213f8e2c",
        "Created": "2023-01-28T05:17:32.3279321Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "ec2a7d76e74f24a5749b6f0a9da48ce10022dd65f03bae500593f389c96bbf7e": {
                "Name": "recursing_dirac",
                "EndpointID": "3f6213efe3a3c30f402d27a642169117989405e077f5416bbbc2f706bce79c14",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

You can see the IP addresses of the containers, however you cannot ping them from the host. To access a service in a container you need to publish the container service port(s).