Dockerlab 106 Docker Networking

access_time2 mins remaining
Dockerlab 106 Docker Networking

About this Lab

subjectLast updated Oct 20, 2021
account_circleWritten by www.ShareLearn.net

1. Overview

image

2. Demo

In case you prefer a video, check below our YouTube video for this lab

3. Create docker hub account.

Create docker hub account. Docker Hub skip this step if you already have one

image

4. Open Play with docker

Open Play with Docker

image

login with your docker hub account.

imageClick on start imageIt will start a 4 hr session image

5. Add new instance

click on + ADD NEW INSTANCE

imagecomment]: ![screenshot}}

6. List docker networks

Task: List all docker networks

Solution
docker network ls

7. Create a network

Task: create a new bridge network

Solution
docker network create -d bridge mbn

8. Run a container

Task: Run a container web with image nginx and new network, expose port 8080 as 80

Solution
docker run -d -p 8080:80 --name web --network=mbn nginx

9. Inspect a container

Task: Inspect network settings of container created in previous step

Solution
docker inspect web
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' web

10. Run a container

Task: Run a container jumphost with image alpine and connect to it

Solution
docker run -it --name jumphost alpine

11. Access web from container

Task: Access port 80 of container web from jumphost

Solution
wget -T 3 172.19.0.2

12. Change container network

Task: Change network used by container jumphost to mbn

Solution
docker network connect mbn jumphost

13. Start container

Task: Start container jumphost

Solution
docker start jumphost

14. Access web from container

Task: Connect to jumhost container and access port 80 of container web

Solution
docker exec -it jumphost sh

this command will connect to container jumphost shell

wget -T 3 172.19.0.2

try to access container web from jumphost

this time it will download index.html file

cat index.html

it will display nginx welcome page

15. Inspect docker network

Task: Inspect docker network mbn

Solution
docker inspect mbn

check network mbn

you will observe that both containers are connected to it

16. Change container network

Task: Disconnect container web and jumphost from network mbn

Solution
docker network disconnect mbn jumphost
docker network disconnect mbn web

17. List docker networks

Task: List all docker networks

Solution
docker network ls

18. Check docker info

Task: Check docker info

Solution
docker info
docker info | grep -i network

19. docker network

Task: Check option for docker network command

Solution
docker network

20. Cleanup

Task: Delete all open nodes/instances and close session

  1. Select the node and click on DELETE
  2. Repeat same for any other open nodes
  3. click close session

cleanup}}


21. Conclusion

Click on ‘Submit Feedback’ on the bottom left of the page to submit any questions/feedback.
bug_report Submit feedback