Dockerlab 106 Docker Networking

Step 0 : Create docker hub account. https://hub.docker.com

Step 1 : Open Play with Docker or login in below with your docker hub account.

Step 2 : Click on start

Step 3 : It will start a 4 hr session, click on + ADD NEW INSTANCE

Step 4 : Click in terminal and press enter.

Step 5 : docker network ls

  • display list of all networks

Step 6 : docker network create -d bridge mbn

  • create a new bridge network

Step 7 : docker network ls

  • display list of all networks

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

  • run a container with port 8080 mapped to 80

  • use --network to configure it to use new network mbn

Step 9 : docker inspect web

  • you will notice that container is using my-bridge-network network

  • take note of ip address

Step 10 : docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' web

  • you can use format with inspect to filter output to show only IP address

Step 11 : docker run -it --name jumphost alpine

  • create a new container with name jumphost using image alpine

Step 12 : wget -T 3 172.19.0.2

  • Try access web container from new container

  • exit out of container

Step 13 : docker network connect mbn jumphost

  • connect container jumphost to network mbn

Step 14 : docker start jumphost

  • start container again

Step 15 : docker exec -it jumphost sh

  • enter container jumphost shell

Step 16 : wget -T 3 172.19.0.2

  • try to access container web from jumphost

  • this time it will download index.html file

Step 17 : cat index.html

  • it will display nginx welcome page

Step 18 : docker inspect mbn

  • check network mbn

  • you will observe that both containers are connected to it

Step 19 : docker network disconnect mbn jumphost

  • disconnect container jumphost from network mbn

Step 20 : docker network disconnect mbn web

  • disconnect container web from network mbn

Step 21 : docker network rm mbn

  • remove network mbn

Step 22 : docker network ls

  • display list of all network

Step 23 : docker info | grep -i network

  • check supported network by running docker instance

Step 24 : docker network

  • it will display list of all options available with docker network command