# Docker Networking

So when we install Docker it actually creates Deafult networks automatically :

a) Bridge : Bridge is the default network a container gets attach to&#x20;

\>> The Bridge network is a private internal network created by Docker on the HOST. All containers attach ot it by default & they get an INTERNAL IP address using in the range 172.17....series.   The container can access get each other using this internal IP if required.&#x20;

\>> To access any of these containers from the outside world maps the port of these containers to ports on the Docker HOST.

\>>Another way to access the containers externally is to associate the container to the HOST network. This takes out any network isolation between the Docker HOST & the Docker container meaning if we want to run a Webserver on port 5000 in a web app container it is automatically accessible on the same port externally without requiring any port mapping as the Web container used the HOST network . This would also mean that unlike before we will now not be able to run multiple web containers on the same HOST & on the same port as port is now common to all containers in the HOST networks.

b) none : With the none network the container are not attached to any network & doesn't have any access to the external netwoork or other containers. They run in an isolated network.

c) host&#x20;

![](/files/-MEaU-xl0iZoaELrW5NC)

\>>What if we wish to isolate the containers within the Docker HOST. For example : First two Web containers on internal network 172.17...& the second two containers on a different internal network like 182.18...&#x20;

\>>>By deafult Docker only creates one internal Bridge network . We could create our own internal network using the below command .

\>>Now see  the network settings & the IP addresses assigned to an existing container&#x20;

docker inspect container-name

![](/files/-MEaXFtMlTNc9u2w3qBY)

![](/files/-MEaYPzhwQdH_SzSX2Sl)

\>>>Container can reach each other using their names . For example in the below case we have a webserver & a mysql database container running on the same node. How do we my webserver to access my database on the database container . One thing we could do is to use the internal IP address assigned to the mysql container which is in this case is 172.17.0.3 . But this is not very ideal bcoz it is not guaranteed that the container will get the same IP when the system reboots .&#x20;

\>>The right way to do it is to use the container name . All container in a Docker HOST can resolve each other with a name of the container . Docker had built-in DNS server that helps the container to resolve each other using the container name . The built-in DNS server always runs at address 127.0.0.11 .

\>>So how does Docker implement networking ? Ans is Docker uses network namespaces that creates a separate namespace for each container . It then uses virtual ethernet pairs to connect containers together.&#x20;

&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://architectures.gitbook.io/project/docker/docker-engine-storage-and-networking/docker-networking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
