Coder Social home page Coder Social logo

docker-networks's Introduction

docker-networks

open bridge-network branch with git checkout bridge-network. Run docker-compose up -d and you see that it creates two container named alice and bob. By entering the alice's container with docker exec -ti alice ash we can ping bob and see that alice and bob can communicate !

You can check the docker-compose.yml file and see that we have just declared our two container with no netword at all but alice and bob can communicate. This is because by default docker create all containers in a network called bridge. This allows to the containers to communicate between them but we don't always want that.

And here comes the docker networks ! Before switching branch it is better to run docker-compose down so all the networks and containers created are deleted. Now go to the same-network branch to continue.

You can open the docker-compose.yml file and see that we only add a network "HOME_NET" and add alice and bob to it with an ip and a default driver which is the bridge. Now you can rerun docker-compose up -d and check the connectivity between alice and bob and see that it still works now you can even check by pinging the address in the docker-compose.

So we can create a network but the containers still have total connectivity between them. This chapter was just to show how to declare a network and assign a network to a container. Now we will dig more into the seperation of the containers in the branch two-networks. Don't forget to run docker-compose down before switching ;).

You see a new file called "router.sh" but don't pay attetion to it for now. In the docker-compose.yml we have created two networks "ALICE_NET" and "BOB_NET" and assigned each containers to its network address. Now if you test the connectivity between alice and bob you will see that it doesn't work anymore. Now that the containers are in two different networks we can no more test with ping bob, we have to use the ip so ping 10.1.0.2 (all the packages will be lost). This is because all different networks in docker will be seperate by default. To connect them we will need a routage between them.

There router.sh comes in. You can execute the file in sudo sudo ./router.sh to add two rules of routage. One to say that you accept the traffic from alice's IP to bob's IP and another one to say that you accept the traffic from bob's IP to alice's IP. Now that the rules are declared the ping should pass in both way.

docker-networks's People

Contributors

severinrobert avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.