If you want to do this for a docker swarm, you have to change the commands. The network driver "bridge" does not work in swarm mode:
(How to run a container inside a swarm take a look here)
Even if you create your bridge on every node.docker service create --network mybrigde --name helloworld alpine ping 192.168.178.1 Error: No such network: mybrigde
You have to configure an overlay network:
And then you can deploy your service like this:alpine:~# docker service create --network myoverlay --name helloworld alpine ping 192.168.178.1
alpine:~# docker service create --replicas 2 --network myoverlay --name helloworld alpine ping 10.200.0.1 ij613sb26sfrgqknq8nnscqeg overall progress: 2 out of 2 tasks 1/2: running [==================================================>] 2/2: running [==================================================>] verify: Service converged
Verification:
On each docker swarm node you can find now:alpine:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6193ebb361fa alpine:latest "ping 10.200.0.1" 12 seconds ago Up 11 seconds helloworld.1.9zoyocdpsdthuqmlk4efk96wz alpine:~# docker logs 6193ebb361fa PING 10.200.0.1 (10.200.0.1): 56 data bytes 64 bytes from 10.200.0.1: seq=0 ttl=64 time=0.344 ms 64 bytes from 10.200.0.1: seq=1 ttl=64 time=0.205 ms 64 bytes from 10.200.0.1: seq=2 ttl=64 time=0.184 ms
node2:~# docker network ls NETWORK ID NAME DRIVER SCOPE 5019841c7e25 bridge bridge local 6e795c964251 docker_gwbridge bridge local 9d9fa338a975 host host local 273dc1ddbc57 mybrigde bridge local siiyo60iaojs myoverlay overlay swarm 9ff819cf7ddb none null local
and after stopping the service (docker service rm helloworld) the overlay "myoverlay" is removed again:
node2:~# docker network ls NETWORK ID NAME DRIVER SCOPE 5019841c7e25 bridge bridge local 6e795c964251 docker_gwbridge bridge local 9d9fa338a975 host host local 273dc1ddbc57 mybrigde bridge local 9ff819cf7ddb none null local
Thanks for sharing the very useful info about DevOps and please keep updating........
ReplyDeleteDevOps Training
DevOps Online Training
DevOps Training in Ameerpet
Thanks for posting such useful information. You have done a great job.
ReplyDeleteDocker and Kubernetes Training
Kubernetes Online Training
Docker Online Training
Docker Training in Hyderabad
Thanks for sharing this information. I really Like Very Much.
ReplyDeletebest devops online training