The Docker Bridge Network - Docker networks part 1

Опубликовано: 03 Октябрь 2024
на канале: OneMarcFifty
35,322
1.3k

MANY THANKS TO ALL MY PATRONS on   / onemarcfifty   !!!

Many thanks for your replies to the poll - your wish is my command and here is the episode on docker networks. As there is so much to tell about docker networks, we will talk about Bridges in this episode. In the next episode we will talk about the host and macvlan network. Networking with Docker, docker bridge networks and docker host and macvlan networks as well as docker-compose are subjects of this series. We will define the networks in the Portainer Networking section

0:00 Intro
1:23 TLDR / TLDW / Chapters
1:42 Describing the setup nginxdemos/hello
2:08 What do we need ?
3:10 Pull the image
4:00 examining the container
5:33 IP Connectivity on the bridge
7:30 Network access
7:55 Hostnames
8:33 Name resolution default bridge
9:22 Port mapping
10:15 The bridge is NAT-ed
11:10 user defined bridges
13:26 Summary bridges
14:00 automate with docker-compose
18:03 Outlook, wrap-up

Here's the list of the commands / steps used in the video:

Portainer Documentation is here: https://documentation.portainer.io/v2...

sudo apt install docker.io
(on a Pi it may be called docker-ce)

One liner to start portainer:

docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer-ce

(In portainer, click on "Networks" on the left, you'll see the networks)
(on the command line)

docker network ls

(Pulling the image and running it)
docker run -d nginxdemos/hello

(in Portainer, Containers Menu, then "Add Container")
(Finding the IP address - click on the container name in Portainer)

Default Bridge IP is usually 172.17.0.0/24, the docker host is 172.17.0.1

(Click on the container name and Select "Duplicate/Edit" to clone it)
In order to execute shell (/bin/ash) on the command line

docker exec -it CONTAINERNAME /bin/ash

Commands I type INSIDE the containers:

ip addr
hostname
ip route
ping 172.17.0.x
ping 8.8.8.8
ping www.google.com

Create the image with port mapping and container name:

docker run -d --name nginx1 -p 81:80 nginxdemos/hello
docker run -d --name nginx2 -p 82:80 nginxdemos/hello
(now you can browse to localhost:81 or localhost:82)

Create the bridge network:

docker network create -d bridge --subnet 172.172.0.0/24 --gateway 172.172.0.1 --ip-range 172.172.0.128/25 --attachable marcsbridge

In order to run the containers on the user defined bridge:

docker run -d --name nginx1 -p 81:80 --network marcsbridge nginxdemos/hello
docker run -d --name nginx2 -p 82:80 --network marcsbridge nginxdemos/hello

Install docker-compose:

sudo apt install docker-compose

The docker compose file can be found here: https://github.com/onemarcfifty/docke...
The Microsoft Visual Studio Code Site is here: https://code.visualstudio.com/Download

(Download the .deb for Ubuntu/Debian, you will then find the File in your Downloads directory. You can then install it with):

sudo dpkg -i (Filename)
for example
sudo dpkg -i code_1.56.0-1620166262_amd64.deb

In order to have the docker-compose extension in Visual Studio Code, select View-Extensions. There are many extensions available, e.g. "Docker Extension Pack" or "Docker Explorer" by Jun Han, or "Docker" by Microsoft or "Docker Compose" by p1c2u

Command line compose up :

docker-compose -f "docker-compose.yml" up -d --build

Please support me on patreon:   / onemarcfifty  
My youtube channel:    / onemarcfifty  
Marc on Twitter:   / onemarcfifty  
Marc on Facebook:   / onemarcfifty  
Marc on Reddit:   / onemarcfifty  
Chat with me on Discord:   / discord  




Licence-free music on / Lizenzfreie Musik von https://www.terrasound.de/lizenzfreie... music on / Lizenzfreie Musik von https://www.terrasound.de/lizenzfreie...


The docker logo from Wikimedia Commons By dotCloud, Inc. - File:Docker (container engine) logo.png, Apache License 2.0, https://commons.wikimedia.org/w/index...


The Thumbnail of this video is under the Apache 2.0 License: https://www.apache.org/licenses/LICEN...