Docker/C3/Docker-Networking/English
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. |