# Juniper - Docker Network

## Resources

* [Docker Networking - Juniper](https://www.youtube.com/watch?v=MGBAXJnoqbA\&t=2s)

### Contents

| Table Of Contents                                                       |
| ----------------------------------------------------------------------- |
| [Network Types Available to Docker](#network-types-available-to-docker) |
| [Docker CLI](#docker-cli)                                               |
| [Create Custom Network](#create)                                        |

## Network Types Available to Docker

Docker uses a pluggable networking sub-system and by default have:

* <mark style="color:purple;">**`bridge`**</mark> - creates a Linux virtual bridge and attaches the container to the bridge port
* <mark style="color:purple;">**`host`**</mark> - attaches the container to the host network
* <mark style="color:purple;">**`none`**</mark> - container has only a loopback interface
* <mark style="color:green;">Orchestrators such as K8's and OpenShift may implement network functionality through Docker network plugins to enable multi-host  networking which giver more options available.</mark>\ <mark style="color:green;">We will focus on options available on a default single host deployment</mark>

## Bridge Networks

![](/files/tSZwbu44P6wcTterQdSZ)

The above is the default bridge when you install docker. Its called 'docker0' and any containers created will be assigned an IP address from this range of 172.17.0.0/16).\
From the above diagram we see 2 apps deployed, each with an assigned IP of <mark style="color:orange;">**172.17.0.2/16**</mark> and <mark style="color:orange;">**172.17.0.3/16**</mark><mark style="color:orange;">.</mark> The docker itself will get the <mark style="color:yellow;">.1 address</mark>

Now the link between the container and the bridge - on the <mark style="color:yellow;">CONTAINER</mark> end it will have an interface of <mark style="color:blue;">eth0</mark> and then from the perspective of the Linux Kernel, these will be 'virtual Ethernet" interfaces (v ethxx) and followed on by randomly generated set of numbers.

Be <mark style="color:red;">**default**</mark> it also does <mark style="color:orange;">**SOURCE NAT**</mark> using the <mark style="color:green;">IP tables function</mark> and thus allowing access <mark style="color:red;">**TO**</mark> the internet\
What we will also see when we do <mark style="color:blue;">**"port-mapping"**</mark> to expose a container port that's actually going to result in a <mark style="color:orange;">**DESTINATION NAT**</mark> rule  which will allow access from the internet (public) to reach these containers through specific <mark style="color:blue;">**PORTS**</mark> on an interface on the <mark style="color:yellow;">**HOST**</mark> operating system.

### Docker CLI

-Check if we have any containers running: <mark style="color:orange;">`docker container list`</mark> \
-Check to see the networks available: <mark style="color:orange;">`docker network list`</mark>\
-Check from the perspective of the Linux kernel: <mark style="color:orange;">`ip a`</mark>  will see '<mark style="color:green;">docker0'</mark> which represents the <mark style="color:green;">'bridge0' network you see in the above command. This has the IP of 172.17.0.1 which is the DG for all containers attached to that default network.</mark>\
-Check virtual bridges using the the bridge utility (<mark style="color:purple;">`apt install bridge-utils`</mark>) : <mark style="color:orange;">`brctl show`</mark>\
which will show available bridges (default will show docker0 bridge with no attached interfaces)\
-Check ip tables - specifically the NAT table: <mark style="color:orange;">`sudo iptables -t nat --list`</mark> here we can see that there is one bridge in place 'docker0' and a rule (source based NAT) which will masquerade any 172.16.17.0/16 IP address to the docker 0 bridge IP&#x20;

![](/files/kOLa1uboTSBZM57XzKUD)

### Create Custom Network

We are going to use the <mark style="color:green;">'docker network create'</mark> command with a few options:\ <mark style="color:green;">--driver</mark> (here we will chose the 'bridge' driver, - we can see what drivers are available from the 'docker network list'  and look for 'DRIVER". It is the 'default' driver but we will specify it anyway\
-o (custom options) for this driver , and name this <mark style="color:green;">bridge interface</mark> "com.docker.network.bridge.name=appbr0" --subnet=172.200.0.0/16 and name of this <mark style="color:green;">NETWORK</mark> we will call <mark style="color:green;">'app\_</mark>*<mark style="color:green;">net'</mark>*

```
docker network create --driver=bridge -o "com.docker.network.bridge.name=appbr0" --subnet 172.200.0/16 app_net
```

![](/files/tTOhtedMo8EfSbNg4ReL)

Here we can see a <mark style="color:green;">new network</mark>  called "app\_net" was created using the "bridge driver " as well as the IP address allocated to it with the first usable address allocated as the DG of any containers attached to THAT particular bridge.

Using the 'bridge utils' brctl show we can see the new bridge interface (<mark style="color:blue;">appbr0</mark>) shown below

![](/files/oMIibmbcmkyDxWZhBQaT)

We can also inspect the details of any of the networks using the \ <mark style="color:yellow;">`docker network inspect <network-name>`</mark>

```
docker network inspect bridge
docker network inspect app_net
```

This is displayed in JSON format

![](/files/GKGmWUc6cARbsnR9oDAJ)


---

# 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://devops.microcisco.com/docker/what-is-docker/juniper-docker-network.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.
