The default docker bridge interface "docker0":

Docker by default creates a network for the containers on a host, it is called the docker0 bridge network as you can see below:


Creating a user-defined network:

If we don't the driver type, docker uses the default "bridge" network:


--driver : is the driver implemented by the network.
The options include "bridge" and "overlay". There are also other third-party drivers as well like "weave" for example.

Inspecting a network:

The below command allows us to see the containers connected to the network, the IP address, ... 


If we don't specify a driver , docker uses the default bridge driver.

Deleting a network:

Before deleting a network, we need to make sure that we have disconnected all the containers connected to it, using the below command:


Then, we can remove the network:


We could use the network_name or the network ID that we can get using the below:


Connecting containers to a network:

If we don't mention any network the container gets attached to the default docker0 bridge as below:



Remark:

When referring to the "debian1" container, we could use the first two characters if they are unique among the other containers.

We then check the interfaces inside the debian1 container:


We run the below commands to disconnect the container debian1 from the default bridge network and we connect it to the new net_1 network:


Then, we recheck the address of the container:


We see that the address has changed, and that the container is now connected to the new network net_1 "172.21.0.2/16".

We could also use the below command to see which containers are attached to the "net_1" network:


Connecting a container to a network with the "run" command:

To connect a container to a specific network right after we run it, we use the below command:


Brando Sabatini and Ikbal C ©. Powered by Blogger.