Docker Networks part 1 – Docker Bridge Networks

33 Comments



MANY THANKS TO ALL MY PATRONS on https://www.patreon.com/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.0/deploy/ceinstalldocker/

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/docker-networks
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: https://www.patreon.com/onemarcfifty
My youtube channel: https://www.youtube.com/onemarcfifty
Marc on Twitter: https://twitter.com/onemarcfifty
Marc on Facebook: https://www.facebook.com/onemarcfifty/
Marc on Reddit: https://www.reddit.com/user/onemarcfifty
Chat with me on Discord: https://discord.com/invite/DXnfBUG

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

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.php?curid=52332268

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

source

33 Comments
    • blank
      gotelldonn
      May 16, 2022 13:52 pm Reply

      Incredibly clear information on docker networks. Keep up the great work!

    • blank
      kay bax
      May 16, 2022 13:52 pm Reply

      This was very instructive and easy to follow. Thank you.

    • blank
      Ivan Hansson
      May 16, 2022 13:52 pm Reply

      So impressed of your way of explain things. Keep up the good work!

    • blank
      Robert Danzl
      May 16, 2022 13:52 pm Reply

      Schade das es das Video nicht in deutsch gibt

    • blank
      Dylan Campbell
      May 16, 2022 13:52 pm Reply

      This was brilliant, thanks!

    • blank
      Yarbin Malawi
      May 16, 2022 13:52 pm Reply

      I could not get it to work on WSL when I went to the IP address at 172.17.0.x

    • blank
      Sunny Yang
      May 16, 2022 13:52 pm Reply

      Great tutorial! Many thanks!!

    • blank
      unmesh59
      May 16, 2022 13:52 pm Reply

      I've just started to learn Docker and used this tutorial on an Ubuntu 21.04 VM running on ESXi7. I couldn't believe how much I learned in a very short time!

      Thanks, Marc.

    • blank
      Curso de Robotica
      May 16, 2022 13:52 pm Reply

      Amazing tutorial!! I loved the comparison between portainer and the comand line!! Now I have the networking clear!! Thank you

    • blank
      Jaysun Kreuze
      May 16, 2022 13:52 pm Reply

      You lost me at Microsoft. It's unnecessary.

    • blank
      Joaquín Vacas Verísimo
      May 16, 2022 13:52 pm Reply

      I've just found this channel and I really enjoy every damn video.
      Thank you so much!

      A firmly handshake from Spain! 🇪🇸

    • blank
      BufferOverflow
      May 16, 2022 13:52 pm Reply

      I have an expressjs app that talks to FFmpeg image that resides on another container, how do I send commands without having to create a web server in the FFmpeg container. Thank you

    • blank
      Gaming Cheap
      May 16, 2022 13:52 pm Reply

      Thank you!

    • blank
      WyRura
      May 16, 2022 13:52 pm Reply

      Great video, very well explained. Thank you.

    • blank
      John U
      May 16, 2022 13:52 pm Reply

      After watching other explanations on Docker Bridge Networks and not understanding, this video explains it perfectly !
      Excellent

    • blank
      krishna panjiyar
      May 16, 2022 13:52 pm Reply

      This is the best docker networking tutorial available in the web. I became a big fan of yours.

    • blank
      Irtibat Kisileri
      May 16, 2022 13:52 pm Reply

      how nicely you put topics thanks.

    • blank
      David Mahon
      May 16, 2022 13:52 pm Reply

      Thank you Marc – very informative and well-presented.

    • blank
      Lee Miller
      May 16, 2022 13:52 pm Reply

      Very informative, thank you. There are far too many videos out there that are just like "use host" or "use bridge" and never explain why. Then if things don't work you're left on your own to figure it out with no real understanding of what is going on.

    • blank
      Лучшие практики программирования
      May 16, 2022 13:52 pm Reply

      On "Compose Up" from vscode I got the error:
      "ERROR: Couldn't connect to Docker daemon – you might need to run docker-machine start default."

      After a while I managed to compose up from a terminal: "docker-compose -f "docker-compose.yml" up -d –build".

      Two containers were created which I could check with the terminal command "sudo docker container ls".
      Both work fine and I can reach them from a web browser, but I cannot see newly created containers in portainer.

      By the way the terminal command "sudo docker container ls" shows me only the containers created from the terminal, but not the containers created from portainer including the portainer itself.

    • blank
      Ameen Al-Azzawi
      May 16, 2022 13:52 pm Reply

      I did the same steps on Windows 10 host, the IP address of the first container "172.17.0.4", doesn't show anything in the browser.

    • blank
      iVan General
      May 16, 2022 13:52 pm Reply

      You are the best instructor! thanx for you work!

    • blank
      Sebstian K.
      May 16, 2022 13:52 pm Reply

      Great video and good information.

      I have one question. I have docker on my raspberry installed.
      When i install Visual Studio Code on my computer, how do i connect to the raspberry docker instance?

    • blank
      Chris DePalma
      May 16, 2022 13:52 pm Reply

      you should have more subscribers

    • blank
      P S
      May 16, 2022 13:52 pm Reply

      do you have experience with separate network in k8s clusters between namespaces ?

    • blank
      Mike Pacholik
      May 16, 2022 13:52 pm Reply

      Thank you. I have been wondering how networking worked in Docker. I learned so much.

    • blank
      M.Ubaid Ullah Khan
      May 16, 2022 13:52 pm Reply

      Really liked the way you described. Keep it up

    • blank
      Timothy Altmann
      May 16, 2022 13:52 pm Reply

      Great video, cannot wait for the next on macvlan!

    • blank
      TurboMyPC
      May 16, 2022 13:52 pm Reply

      Docker network Macvlan, docker-compose, and mptcp server would be an amazing project to see.

    • blank
      DHARUN PAZHANIVEL
      May 16, 2022 13:52 pm Reply

      Just waiting for your next episode on this. I love your work Marc 👍👍👍👍

    • blank
      tom cooper
      May 16, 2022 13:52 pm Reply

      darauf habe ich gewartet..

    • blank
      squalazzo
      May 16, 2022 13:52 pm Reply

      very clear, well done, thanks!

    • blank
      jeytis72
      May 16, 2022 13:52 pm Reply

      Awesome! I have never come across such a clear explanation on how dockers and docker networks work. Thank you very much

Leave us a comment