Docker networking contd..
- Lets look at the following scenario
- As number of Docker Hosts increase the complexity of running containers becomes difficult to manage.
- A container in one host (srv1) trying to connect to container in other host (srv3) is not possible with bridge network
- Failure scenarios:
- What happens if the srv1 is down
- What happens when a container in srv1 is down
- Performing the above actions are tedious.
- Lets just think of networking perspective, docker has a mode called as swarm which enables multi-host docker networking and also it gives orchestration features.
- Refer Here for the blog
- Refer Here for the networking and interfaces
- All the nodes should be reachable to each other
- docker should be installed on all the nodes
- Create two linux servers and install docker in it
- Select any linux server (node-1 – powershell in images) and initialize swarm
qtdevops@dockernode-1:~$ docker swarm init --advertise-addr "10.2.0.6" Swarm initialized: current node (qo5x9l0pngi8k20zeisrv5lc9) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-3prx9d5k19977wurpimwl1v0ufon8e22u6uns3s3d38aa4c3rx-9stw2ke6ytpwutuggn1zb0kn3 10.2.0.6:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
- On the manager two extra docker networks will be created
Now execute docker swarm join command on the node-2
- Lets look at networks
- Communication from one to other container will look as shown below
- Lets see the list of nodes in docker swarm manager
- Lets create a service of nginx
docker service create --replicas 2 --name nginx-srv nginx