{"id":6012,"date":"2021-09-15T16:56:14","date_gmt":"2021-09-15T16:56:14","guid":{"rendered":"https:\/\/www.geekdecoder.com\/?p=6012"},"modified":"2021-09-15T16:56:14","modified_gmt":"2021-09-15T16:56:14","slug":"docker-network-commands","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2021\/09\/15\/docker-network-commands\/","title":{"rendered":"Docker Network and Other Commands"},"content":{"rendered":"<p>Docker Network commands<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\"># docker network ls\nNETWORK ID     NAME                  DRIVER    SCOPE\n234dbbb8d381   bridge                bridge    local\ne23bbf6e6a54   docker-hive_default   bridge    local\ne284120f22c7   host                  host      local\n019daa8ddd49   none                  null      local\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">$ docker ps --format &quot;table {{.ID}}\\t{{.Status}}\\t{{.Names}}&quot;\nCONTAINER ID   STATUS             NAMES\n608fe6f7a1c4   Up About an hour   docker-tutorial\n<\/pre>\n<p>Docker Example<\/p>\n<p>To illustrate this, we will use a Hive and Hadoop environment, containing 5 Docker Containers from &#8211; https:\/\/github.com\/mesmacosta\/docker-hive.<br \/>\nSince I am on windows, I use Github desktop.<\/p>\n<p>Launch Github desktop and then go to File &gt;&gt; Clone Repository &gt;&gt; URL.<\/p>\n<p><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2021\/09\/clone1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6020\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2021\/09\/clone1.png\" alt=\"\" width=\"955\" height=\"662\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/09\/clone1.png 955w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/09\/clone1-300x208.png 300w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/09\/clone1-768x532.png 768w\" sizes=\"auto, (max-width: 955px) 100vw, 955px\" \/><\/a><\/p>\n<p>Go to https:\/\/github.com\/mesmacosta\/docker-hive &#8211; Click on Code &gt; Copy. Paste URL into Github Desktop. Click Clone.<\/p>\n<p><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2021\/09\/clone2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-6018\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2021\/09\/clone2-1024x269.png\" alt=\"\" width=\"900\" height=\"236\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/09\/clone2-1024x269.png 1024w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/09\/clone2-300x79.png 300w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/09\/clone2-768x202.png 768w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/09\/clone2.png 1239w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/a><\/p>\n<p>Now open command prompt or Powershell &#8211; AS ADMINISTRATOR &#8211; and go to the directory where the docker files are located. In my case its in Documents > Github > docker-hive.<\/p>\n<p>Now let&#8217;s start up those containers:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# docker-compose up -d\n<\/pre>\n<p>Note: If you receive this error:<br \/>\nError response from daemon: Ports are not available: listen tcp 0.0.0.0:50070: bind: An attempt was made to access a socket in a way forbidden by its access permissions.<\/p>\n<p>Run this in command prompt or PS:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nnet stop winnat\nnet start winnat\n<\/pre>\n<p>We can see 5 containers:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n&gt;docker ps --format &quot;table {{.ID}}\\t{{.Status}}\\t{{.Names}}&quot;\nCONTAINER ID   STATUS                   NAMES\n30714f65fc36   Up 2 minutes             docker-hive_hive-metastore_1\ncc281caa92ba   Up 2 minutes             docker-hive_hive-server_1\n66aed41cdc5e   Up 2 minutes             docker-hive_hive-metastore-postgresql_1\nd90c10f7cfe6   Up 2 minutes (healthy)   docker-hive_datanode_1\nbaf998183015   Up 2 minutes (healthy)   docker-hive_namenode_1\n<\/pre>\n<p>Next let&#8217;s check our Docker networks:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n&gt;docker network ls\nNETWORK ID     NAME                  DRIVER    SCOPE\n234dbbb8d381   bridge                bridge    local\nd438c2ba7c56   docker-hive_default   bridge    local\ne284120f22c7   host                  host      local\n019daa8ddd49   none                  null      local\n<\/pre>\n<p>By default docker compose sets up a single network for your app. And your app\u2019s network is given a name based on the \u201cproject name\u201d, originated from the name of the directory it lives in.<\/p>\n<p>So since our directory is named docker-hive, this explains the new network.<\/p>\n<p>Getting more information.<\/p>\n<p>Docker inspect can retrieve low-level information on Docker objects. You can pick out any field from the returned JSON.<\/p>\n<p>Let&#8217;s get the IP Address from the dockerhive_datanode.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n&gt;docker ps --format &quot;table {{.ID}}\\t{{.Status}}\\t{{.Names}}&quot;\nCONTAINER ID   STATUS                   NAMES\n30714f65fc36   Up 2 minutes             docker-hive_hive-metastore_1\ncc281caa92ba   Up 2 minutes             docker-hive_hive-server_1\n66aed41cdc5e   Up 2 minutes             docker-hive_hive-metastore-postgresql_1\nd90c10f7cfe6   Up 2 minutes (healthy)   docker-hive_datanode_1\nbaf998183015   Up 2 minutes (healthy)   docker-hive_namenode_1\n<\/pre>\n<p>Get the container ID from the above command to find the following:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$ docker inspect -f &#039;{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}&#039; d90c10f7cfe6\n172.20.0.2\n<\/pre>\n<p>Docker Logs<\/p>\n<p>How to check Docker logs<br \/>\nsudo docker logs <container_id> where <container_id> is the ID of the docker container<\/p>\n<p>Get Docker Container:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# sudo docker ps --format &quot;table {{.ID}}\\t{{.Status}}\\t{{.Names}}&quot;\n<\/pre>\n<p>Now view the logs:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$ sudo docker logs d90c10f7cfe6   \n<\/pre>\n<p>Docker Ports<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$ docker container ls --format &quot;table {{.ID}}\\t{{.Names}}\\t{{.Ports}}&quot; -a\nCONTAINER ID   NAMES             PORTS\na624f0ae744e   cool_moore\na0d9f2b7ce84   zealous_mclean    0.0.0.0:80-&gt;80\/tcp, :::80-&gt;80\/tcp\n<\/pre>\n<p>docker inspect<\/p>\n<p>This method allows one to return low-level information on the container or image.<br \/>\nSyntax<\/p>\n<p>docker inspect Container\/Image <\/p>\n<p>Select IP <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# docker inspect c52b91aa0dea | grep -i ip\n<\/pre>\n<p>Ports<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ndocker inspect c52b91aa0dea | grep -i port\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Docker Network commands # docker network ls NETWORK ID NAME DRIVER SCOPE 234dbbb8d381 bridge bridge local e23bbf6e6a54 docker-hive_default bridge local e284120f22c7 host host local 019daa8ddd49 none null local $ docker ps &#8211;format &quot;table {{.ID}}\\t{{.Status}}\\t{{.Names}}&quot; CONTAINER ID STATUS NAMES 608fe6f7a1c4 Up About an hour docker-tutorial Docker Example To illustrate this, we will use a Hive and &#8230; <a title=\"Docker Network and Other Commands\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2021\/09\/15\/docker-network-commands\/\" aria-label=\"Read more about Docker Network and Other Commands\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-6012","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/6012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=6012"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/6012\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=6012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=6012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=6012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}