{"id":892,"date":"2020-08-04T12:10:49","date_gmt":"2020-08-04T12:10:49","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=892"},"modified":"2020-08-05T04:42:27","modified_gmt":"2020-08-05T04:42:27","slug":"docker-network","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2020\/08\/04\/docker-network\/","title":{"rendered":"Docker network"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Learn by example<\/h2>\n\n\n\n<p>In this blog let&#8217;s learn how to create a bridge network. By definition &#8211; Bridge networks are usually used when your applications run in standalone containers that need to communicate<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>A bridge network is a Link Layer device which forwards traffic between network segments.<\/p><cite>docker.com<\/cite><\/blockquote>\n\n\n\n<p>When you create a network, Docker engine creates a non-overlapping sub-network for the network by default and for a bridge network you can only have one subnet.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker network<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-pullquote has-background has-vivid-red-background-color is-style-solid-color\"><blockquote class=\"has-text-color has-luminous-vivid-amber-color\"><p>When you create a network, Engine creates a non-overlapping subnetwork for the network by default.<\/p><\/blockquote><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>Usage:\tdocker network COMMAND\n\nManage networks\n\nCommands:\n  connect     Connect a container to a network\n  create      Create a network\n  disconnect  Disconnect a container from a network\n  inspect     Display detailed information on one or more networks\n  ls          List networks\n  prune       Remove all unused networks\n  rm          Remove one or more networks\n\nRun 'docker network COMMAND --help' for more information on a command.<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-pullquote has-background has-vivid-red-background-color is-style-solid-color\"><blockquote class=\"has-text-color has-luminous-vivid-amber-color\"><p>In terms of Docker, a bridge network uses a software bridge which allows containers connected to the same bridge network to communicate, while providing isolation from containers which are not connected to that bridge network.<\/p><\/blockquote><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>docker network create --help\n\nUsage:\tdocker network create &#91;OPTIONS] NETWORK\n\nCreate a network\n\nOptions:\n      --attachable           Enable manual container attachment\n      --aux-address map      Auxiliary IPv4 or IPv6 addresses used by Network driver (default map&#91;])\n      --config-from string   The network from which copying the configuration\n      --config-only          Create a configuration only network\n  -d, --driver string        Driver to manage the Network (default \"bridge\")\n      --gateway strings      IPv4 or IPv6 Gateway for the master subnet\n      --ingress              Create swarm routing-mesh network\n      --internal             Restrict external access to the network\n      --ip-range strings     Allocate container ip from a sub-range\n      --ipam-driver string   IP Address Management Driver (default \"default\")\n      --ipam-opt map         Set IPAM driver specific options (default map&#91;])\n      --ipv6                 Enable IPv6 networking\n      --label list           Set metadata on a network\n  -o, --opt map              Set driver specific options (default map&#91;])\n      --scope string         Control the network's scope\n      --subnet strings       Subnet in CIDR format that represents a network segment<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>docker network create --driver bridge my-nw\n69b3024142339bb32fcf960de3175e3db3aeeca727ec653a27819549ee278e41<\/code><\/pre>\n\n\n\n<p>The command above will allow to define  a network <code>my-nw<\/code> of type <code>--driver bridge<\/code> for the containers to connect-to and use.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker network ls\nNETWORK ID          NAME                DRIVER              SCOPE\na97c7c66f4fd        bridge              bridge              local\nd39ea265c531        host                host                local\nefe4bfd141fe        none                null                local\n69b302414233        my-nw               bridge              local<\/code><\/pre>\n\n\n\n<p>For a container to use this network one can specify the <code>--network<\/code> option with the value <code>my-nw<\/code> for it to utilize<\/p>\n\n\n\n<figure class=\"wp-block-pullquote has-background has-vivid-red-background-color is-style-solid-color\"><blockquote class=\"has-text-color has-luminous-vivid-amber-color\"><p>The Docker bridge driver automatically installs rules in the host machine so that containers on different bridge networks cannot communicate directly with each other.<\/p><\/blockquote><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run --network my-nw --name using-nw samarthya\/mydummycontainer:1<\/code><\/pre>\n\n\n\n<p>Please note <code>Bridge networks apply to containers running on the <strong>same<\/strong> Docker daemon host.<\/code><\/p>\n\n\n\n<figure class=\"wp-block-pullquote has-background has-vivid-red-background-color is-style-solid-color\"><blockquote class=\"has-text-color has-luminous-vivid-amber-color\"><p>When you create or remove a user-defined bridge or connect or disconnect a container from a user-defined bridge, Docker uses tools specific to the operating system to manage the underlying network infrastructure (such as adding or removing bridge devices or configuring <code>iptables<\/code> rules on Linux).<\/p><\/blockquote><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>https:\/\/success.docker.com\/article\/networking<\/li><li>https:\/\/docs.docker.com\/network\/bridge\/<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Learn by example In this blog let&#8217;s learn how to create a bridge network. By definition &#8211; Bridge networks are usually used when your applications run in standalone containers that need to communicate A bridge network is a Link Layer device which forwards traffic between network segments. docker.com When you create a network, Docker engine [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":897,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[34],"tags":[82,91],"class_list":["post-892","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-technical","tag-docker","tag-network","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=892"}],"version-history":[{"count":0,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/892\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/897"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}