Difference between revisions of "Docker/C3/Docker-Networking/English"
(Created page with "<div style="margin-left:1.27cm;margin-right:0cm;"></div> {| border="1" |- || '''Visual Cue''' || '''Narration''' |- | style="border-top:0.5pt solid #000000;border-bottom:0.5pt...") |
|||
Line 1: | Line 1: | ||
− | + | ||
{| border="1" | {| border="1" | ||
|- | |- | ||
Line 5: | Line 5: | ||
|| '''Narration''' | || '''Narration''' | ||
|- | |- | ||
− | | | + | || Show Slide: |
'''Title Slide''' | '''Title Slide''' | ||
− | | | + | || Hello and welcome to the Spoken Tutorial on “'''Docker Networking”.''' |
|- | |- | ||
− | | | + | || Show Slide: |
'''Learning Objectives''' | '''Learning Objectives''' | ||
− | | | + | || In this tutorial, we will learn about: |
− | * | + | * Fundamentals of Docker networking. |
− | * | + | * Connecting containers and establishing communication links. |
− | * | + | * Configuring port exposure and service exposure. |
− | * | + | * Deleting docker network |
|- | |- | ||
− | | | + | || Show Slide: |
'''System Requirements''' | '''System Requirements''' | ||
− | | | + | || To record this tutorial, I am using |
− | * | + | * '''Ubuntu Linux '''OS version '''22.04''' |
− | * | + | * '''Docker version 27.0.2''' |
|- | |- | ||
− | | | + | || Show Slide: |
'''Prerequisite''' | '''Prerequisite''' | ||
− | | | + | || To follow this tutorial, |
− | * | + | * You must have basic knowledge of using Linux terminal |
− | * | + | * For pre-requisite Linux tutorials, please visit this website |
|- | |- | ||
− | | | + | || Show Slide: |
'''Fundamentals of Docker networking''' | '''Fundamentals of Docker networking''' | ||
− | | | + | || |
− | * | + | * Docker networking involves various components and configurations |
− | * | + | * Docker uses network namespaces to isolate network resources. |
− | * | + | * Docker facilitates this through network links and service discovery mechanisms |
|- | |- | ||
− | | | + | || Show Slide: |
'''Types of Docker networks''' | '''Types of Docker networks''' | ||
− | | | + | || |
− | {| | + | {| border=1 |
− | |- | + | |- |
|| Docker provides several types of networks: | || Docker provides several types of networks: | ||
|- | |- | ||
|} | |} | ||
− | * | + | * '''Bridge Network''':It is the default network type |
− | * | + | * '''Host Network''': The Containers share the host’s network stack |
− | * | + | * '''Overlay Network''': It enables communication between containers |
− | * | + | * '''Macvlan Network''': It assigns a MAC address to each container, making it appear as a physical device |
− | * | + | * '''None Network:''' It disables networking for the container |
|- | |- | ||
− | | | + | || |
− | | | + | || In this tutorial we will demonstrate how to use '''Bridge Network.''' |
− | + | ||
− | In this tutorial we will demonstrate how to use '''Bridge Network.''' | + | |
|- | |- | ||
− | | | + | || Open Linux terminal |
'''Create a Docker network''' | '''Create a Docker network''' | ||
Line 69: | Line 67: | ||
Highlight '''network id''' | Highlight '''network id''' | ||
− | | | + | || Open your''' terminal'''. |
− | Open your''' terminal'''. | + | |
Let us first create a docker network. | Let us first create a docker network. | ||
Line 83: | Line 80: | ||
|- | |- | ||
− | | | + | || Type command |
'''docker network ls''' | '''docker network ls''' | ||
− | | | + | || To view all the docker network, type the command |
'''docker network ls''' | '''docker network ls''' | ||
Line 94: | Line 91: | ||
with '''newnetwork''' | with '''newnetwork''' | ||
|- | |- | ||
− | | | + | || Terminal Command: |
Highlight '''container id''' | Highlight '''container id''' | ||
− | | | + | || Next, let's connect containers. |
− | + | We will be using a '''nginx '''docker image. | |
− | + | We'll start a container and connect it to the network using the command as shown. | |
This command runs a container named '''container1''' and connects it to '''newnetwork.''' | This command runs a container named '''container1''' and connects it to '''newnetwork.''' | ||
|- | |- | ||
− | | | + | || Terminal Command: |
Highlight '''container id''' | Highlight '''container id''' | ||
− | | | + | || Similarly, let us run another container named container2 with '''curlimages/curl '''image |
Type the command as shown. | Type the command as shown. | ||
Line 121: | Line 118: | ||
They can communicate with each other. | They can communicate with each other. | ||
|- | |- | ||
− | | | + | || Terminal Command: |
Highlight '''response''' | Highlight '''response''' | ||
− | | | + | || To check the connectivity between containers, we use the command, as shown. |
The containers will return a webpage response. | The containers will return a webpage response. | ||
Line 130: | Line 127: | ||
The response will contain '''nginx''' welcome page in html format | The response will contain '''nginx''' welcome page in html format | ||
|- | |- | ||
− | | | + | || Only narration. |
+ | || Now, let's learn about exposing ports. | ||
− | + | Ports expose Docker container services to the host or other networks | |
− | + | ||
|- | |- | ||
− | | | + | || Terminal Command: |
'''docker run -d -p 8080:80 nginx''' | '''docker run -d -p 8080:80 nginx''' | ||
− | | | + | || For example, to bind port 8080 on your host to port 80 in the '''container''', use |
'''docker space run space hyphen d space hyphen p space 8080:80 space nginx '''and press '''Enter''' | '''docker space run space hyphen d space hyphen p space 8080:80 space nginx '''and press '''Enter''' | ||
Line 148: | Line 145: | ||
We can access this via port '''8080''' on the host machine | We can access this via port '''8080''' on the host machine | ||
|- | |- | ||
− | | | + | || Open Firefox browser. |
Type the URL [http://localhost:8080/ http://localhost:8080] | Type the URL [http://localhost:8080/ http://localhost:8080] | ||
− | | | + | || Now let us view the running nginx web server. |
Open the web browser and type the url | Open the web browser and type the url | ||
Line 158: | Line 155: | ||
|- | |- | ||
− | | | + | || The''' nginx welcome '''page will open |
− | | | + | || This is the welcome page for nginx web server. |
|- | |- | ||
− | | | + | || Terminal Command |
'''docker network ls''' | '''docker network ls''' | ||
Line 167: | Line 164: | ||
All the docker network with network id will appear | All the docker network with network id will appear | ||
− | | | + | || Switching back to the terminal. |
Let us see how to delete a created network. | Let us see how to delete a created network. | ||
Line 178: | Line 175: | ||
|- | |- | ||
− | | | + | || '''docker network rm <NETWORK_ID>''' |
− | + | ||To remove the network we will use the remove command with network id. | |
− | '''docker network rm <NETWORK_ID>''' | + | |
− | + | ||
− | | | + | |
− | + | ||
− | To remove the network we will use the remove command with network id. | + | |
Let us remove the third network from the list. | Let us remove the third network from the list. | ||
Line 192: | Line 184: | ||
Type '''docker space network space rm and paste the id.''' | Type '''docker space network space rm and paste the id.''' | ||
|- | |- | ||
− | | | + | || '''Error appears ''' |
− | | | + | || This error appears because some containers are using the '''newnetwork''' |
To fix this error we have to first stop all the containers using the network '''newnetwork''' | To fix this error we have to first stop all the containers using the network '''newnetwork''' | ||
|- | |- | ||
− | | | + | || '''docker ps -q --filter "network=newnetwork" | xargs docker stop''' |
− | + | || To stop all the containers under the same network. | |
− | + | ||
− | | | + | |
Type the command as shown. | Type the command as shown. | ||
− | |||
It displays the container id that are stopped which used '''newnetwork''' as network | It displays the container id that are stopped which used '''newnetwork''' as network | ||
|- | |- | ||
− | | | + | || Type '''docker space network space rm and paste the id.''' |
− | + | || Now we can remove the network. | |
− | Type '''docker space network space rm and paste the id.''' | + | |
− | + | ||
− | | | + | |
Type '''docker network ls''' | Type '''docker network ls''' | ||
Line 229: | Line 215: | ||
|- | |- | ||
− | | | + | || '''docker network prune''' |
− | + | ||
− | '''docker network prune''' | + | |
A warning will appear | A warning will appear | ||
Line 239: | Line 223: | ||
'''Are you sure you want to continue? [y/N]''' | '''Are you sure you want to continue? [y/N]''' | ||
− | | | + | || You can also remove all the unused '''docker network '''at once. |
− | + | ||
− | You can also remove all the unused '''docker network '''at once. | + | |
For that type | For that type | ||
Line 252: | Line 234: | ||
|- | |- | ||
− | | | + | || Clicking on terminal close button |
− | | | + | || Close the '''terminal window.''' |
|- | |- | ||
− | | | + | || Show Slide: |
'''Summary''' | '''Summary''' | ||
− | | | + | || This brings us to the end of this tutorial. Let us summarize. |
In this tutorial, we learnt about | In this tutorial, we learnt about | ||
− | * | + | * Fundamentals of Docker networking |
− | * | + | * Connecting containers and establishing communication links |
− | * | + | * Configuring port exposure and service exposure |
− | * | + | * Deleting docker network |
|- | |- | ||
− | | | + | || Show Slide: '''About Spoken Tutorial project''' |
− | | | + | || The video at the following link summarizes the '''Spoken Tutorial project'''. |
Please download and watch it | Please download and watch it | ||
|- | |- | ||
− | | | + | || Show Slide: '''Spoken Tutorial Workshops''' |
− | | | + | || The '''Spoken Tutorial Project''' team conducts workshops and gives certificates. |
For more details, please write to us. | For more details, please write to us. | ||
|- | |- | ||
− | | | + | || Show Slide: |
'''Answers for THIS Spoken Tutorial''' | '''Answers for THIS Spoken Tutorial''' | ||
− | | | + | || Please post your timed queries in this forum. |
|- | |- | ||
− | | | + | || Show Slide: '''FOSSEE Forum''' |
− | | | + | || For any general or technical questions on '''Docker''', visit the FOSSEE forum and post your question. |
|- | |- | ||
− | | | + | || Slide: '''Acknowledgement''' |
− | | | + | || '''Spoken Tutorial '''Project was established by the''' Ministry of Education''',''' Government of India'''. |
|- | |- | ||
− | | | + | || Show slide: |
− | + | '''Thank You''' | |
− | | | + | || This is Aditya Kushwaha, a FOSSEE Semester long intern 2024, IIT Bombay, signing off. |
Thanks for joining. | Thanks for joining. | ||
|- | |- | ||
|} | |} |
Latest revision as of 17:11, 4 February 2025
Visual Cue | Narration | |
Show Slide:
Title Slide |
Hello and welcome to the Spoken Tutorial on “Docker Networking”. | |
Show Slide:
Learning Objectives |
In this tutorial, we will learn about:
| |
Show Slide:
System Requirements |
To record this tutorial, I am using
| |
Show Slide:
Prerequisite |
To follow this tutorial,
| |
Show Slide:
Fundamentals of Docker networking |
| |
Show Slide:
Types of Docker networks |
| |
In this tutorial we will demonstrate how to use Bridge Network. | ||
Open Linux terminal
Create a Docker network Type command docker network create newnetwork in terminal Highlight network id |
Open your terminal.
Let us first create a docker network. To create a docker network Type docker space network space create space newnetwork and press Enter Here, newnetwork is the name of the network. We can see a network id as output related to the created network. | |
Type command
docker network ls |
To view all the docker network, type the command
docker network ls Here you can see all the docker networks with newnetwork | |
Terminal Command:
Highlight container id |
Next, let's connect containers.
We will be using a nginx docker image. We'll start a container and connect it to the network using the command as shown. This command runs a container named container1 and connects it to newnetwork. | |
Terminal Command:
Highlight container id |
Similarly, let us run another container named container2 with curlimages/curl image
Type the command as shown. Here the nginx container is serving as the server And we will use the curl container to act as the client Now, both containers are connected to the same network. They can communicate with each other. | |
Terminal Command:
Highlight response |
To check the connectivity between containers, we use the command, as shown.
The containers will return a webpage response. The response will contain nginx welcome page in html format | |
Only narration. | Now, let's learn about exposing ports.
Ports expose Docker container services to the host or other networks | |
Terminal Command:
docker run -d -p 8080:80 nginx |
For example, to bind port 8080 on your host to port 80 in the container, use
docker space run space hyphen d space hyphen p space 8080:80 space nginx and press Enter This command exposes port 80 of the container nginx to port 8080 on the host. Now, service is running on port 80 within the container. We can access this via port 8080 on the host machine | |
Open Firefox browser.
Type the URL http://localhost:8080 |
Now let us view the running nginx web server.
Open the web browser and type the url | |
The nginx welcome page will open | This is the welcome page for nginx web server. | |
Terminal Command
docker network ls All the docker network with network id will appear |
Switching back to the terminal.
Let us see how to delete a created network. Type docker space network space ls Here we can see all the docker networks | |
docker network rm <NETWORK_ID> | To remove the network we will use the remove command with network id.
Let us remove the third network from the list. copy the network_id Type docker space network space rm and paste the id. | |
Error appears | This error appears because some containers are using the newnetwork
To fix this error we have to first stop all the containers using the network newnetwork | |
docker ps -q --filter "network=newnetwork" | xargs docker stop | To stop all the containers under the same network.
Type the command as shown.
| |
Type docker space network space rm and paste the id. | Now we can remove the network.
Type docker network ls To remove the network we will use the remove command with network id. Let us remove the third network from the list. copy the network id Type docker space network space rm and paste the id. The network newnetwork is successfully removed with network id as shown. | |
docker network prune
A warning will appear WARNING! This will remove all custom networks not used by at least one container. Are you sure you want to continue? [y/N] |
You can also remove all the unused docker network at once.
For that type docker space network space prune A warning will appear. Type y and press Enter to continue removing the docker networks | |
Clicking on terminal close button | Close the terminal window. | |
Show Slide:
Summary |
This brings us to the end of this tutorial. Let us summarize.
In this tutorial, we learnt about
| |
Show Slide: About Spoken Tutorial project | The video at the following link summarizes the Spoken Tutorial project.
Please download and watch it | |
Show Slide: Spoken Tutorial Workshops | The Spoken Tutorial Project team conducts workshops and gives certificates.
For more details, please write to us. | |
Show Slide:
Answers for THIS Spoken Tutorial |
Please post your timed queries in this forum. | |
Show Slide: FOSSEE Forum | For any general or technical questions on Docker, visit the FOSSEE forum and post your question. | |
Slide: Acknowledgement | Spoken Tutorial Project was established by the Ministry of Education, Government of India. | |
Show slide:
Thank You |
This is Aditya Kushwaha, a FOSSEE Semester long intern 2024, IIT Bombay, signing off.
Thanks for joining. |