{"id":865,"date":"2020-03-16T19:04:57","date_gmt":"2020-03-17T00:04:57","guid":{"rendered":"http:\/\/zewwy.ca\/?p=865"},"modified":"2020-03-16T19:04:57","modified_gmt":"2020-03-17T00:04:57","slug":"belk-stack-on-docker-part-2-docker-compose","status":"publish","type":"post","link":"https:\/\/zewwy.ca\/index.php\/2020\/03\/16\/belk-stack-on-docker-part-2-docker-compose\/","title":{"rendered":"BELK Stack on Docker <\/br>(Part 2 \u2013 Docker Compose)"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/RV1EqMe.png\" \/><\/p>\n<h1 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"The_Story_Continues\"><\/span><strong>The Story Continues<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>Following on from the last post, today we cover docker-compose to allow for easier deployment of docker images and configurations. As from my previous post you may want to indulge in the same reading I did <a href=\"https:\/\/itnext.io\/docker-102-docker-compose-6bec46f18a0e\">here.<\/a><\/p>\n<p>Past those nice formalities, I find myself missing something&#8230; I&#8217;m not sure what it could be&#8230; oh yeah&#8230;. dependencies!<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/K1XSEbM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/K1XSEbM.png\" alt=\"\" width=\"505\" height=\"137\" \/><\/a><\/p>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"Installing_Docker-Compose\"><\/span>Installing Docker-Compose<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Can I use apt-get?<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/5GNFEA0.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/5GNFEA0.png\" alt=\"\" width=\"1022\" height=\"534\" \/><\/a><\/p>\n<p>Would seem like it&#8230; but<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/tyATp6H.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/tyATp6H.png\" alt=\"\" width=\"399\" height=\"39\" \/><\/a><\/p>\n<p>IT&#8217;s outdated&#8230; \ud83d\ude00<\/p>\n<p>Other way is via pip or <a href=\"https:\/\/docs.docker.com\/compose\/install\/#linux\">the intended way<\/a>&#8230;<\/p>\n<p><a href=\"https:\/\/i.imgur.com\/bTIXryr.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i.imgur.com\/bTIXryr.png\" alt=\"\" width=\"1029\" height=\"145\" \/><\/a><\/p>\n<h2 style=\"text-align: center;\"><span class=\"ez-toc-section\" id=\"Working_with_Docker-Compose\"><\/span>Working with Docker-Compose<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul class=\"\">\n<li id=\"84ba\" class=\"hh hi dt ar hj b hk hl hm hn ho hp hq hr hs ht hu jg jh ji\" data-selectable-paragraph=\"\"><code class=\"hb ij ik il im b\"><strong class=\"hj jj\">docker-compose ps <\/strong><\/code><strong class=\"hj jj\">\u2014<\/strong> lists all the services in a network. This is especially helpful when troubleshooting a service as it will give you the container ID and you can then run <code class=\"hb ij ik il im b\">docker -it exec &lt;ID&gt; bash<\/code> to enter the container and debug as needed.<\/li>\n<li id=\"3606\" class=\"hh hi dt ar hj b hk jk hm jl ho jm hq jn hs jo hu jg jh ji\" data-selectable-paragraph=\"\"><code class=\"hb ij ik il im b\"><strong class=\"hj jj\">docker-compose build<\/strong><\/code><strong class=\"hj jj\"> \u2014 <\/strong>generates any needed images from custom <code class=\"hb ij ik il im b\">Dockerfiles<\/code>. It will not pull images from the Docker hub, only generate custom images.<\/li>\n<li id=\"6099\" class=\"hh hi dt ar hj b hk jk hm jl ho jm hq jn hs jo hu jg jh ji\" data-selectable-paragraph=\"\"><code class=\"hb ij ik il im b\"><strong class=\"hj jj\">docker-compose up <\/strong><\/code><strong class=\"hj jj\">\u2014 <\/strong>brings up the network for the services to run in<\/li>\n<li id=\"80ea\" class=\"hh hi dt ar hj b hk jk hm jl ho jm hq jn hs jo hu jg jh ji\" data-selectable-paragraph=\"\"><code class=\"hb ij ik il im b\"><strong class=\"hj jj\">docker-compose stop<\/strong><\/code><strong class=\"hj jj\"> \u2014 <\/strong>stops the network and saves the state of all the services<\/li>\n<li id=\"f3eb\" class=\"hh hi dt ar hj b hk jk hm jl ho jm hq jn hs jo hu jg jh ji\" data-selectable-paragraph=\"\"><code class=\"hb ij ik il im b\"><strong class=\"hj jj\">docker-compose start <\/strong><\/code><strong class=\"hj jj\">\u2014 <\/strong>restarts the services and brings them back up with the state they had when they were stopped<\/li>\n<li id=\"129c\" class=\"hh hi dt ar hj b hk jk hm jl ho jm hq jn hs jo hu jg jh ji\" data-selectable-paragraph=\"\"><code class=\"hb ij ik il im b\"><strong class=\"hj jj\">docker-compose down<\/strong><\/code><strong class=\"hj jj\"> \u2014 <\/strong>burns the entire Docker network with fire. The network and all the services contained within are totally destroyed.<\/li>\n<\/ul>\n<h2 id=\"4fb8\" class=\"in io dt ar aq ip iq ir is it iu iv iw ix iy iz ja\" style=\"text-align: center;\" data-selectable-paragraph=\"\"><span class=\"ez-toc-section\" id=\"How_to_Docker-Compose\"><\/span>How to Docker-Compose?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p id=\"d442\" class=\"hh hi dt ar hj b hk jb hm jc ho jd hq je hs jf hu dl\" data-selectable-paragraph=\"\">The last big question is: how to write a <code class=\"hb ij ik il im b\">docker-compose.yml<\/code>, and it\u2019s actually very easy and follows a standard formula.<\/p>\n<p id=\"f5c0\" class=\"hh hi dt ar hj b hk hl hm hn ho hp hq hr hs ht hu dl\" data-selectable-paragraph=\"\">Here is a template of what any <code class=\"hb ij ik il im b\">docker-compose.yml<\/code> will look like.<\/p>\n<ul class=\"\">\n<li id=\"4a40\" class=\"hh hi dt ar hj b hk hl hm hn ho hp hq hr hs ht hu jg jh ji\" data-selectable-paragraph=\"\"><strong class=\"hj jj\">Sample Docker Compose Template<\/strong><\/li>\n<\/ul>\n<pre>version: \"2\"\r\n  services:\r\n    &lt;name_of_service&gt;:\r\n      build: &lt;path_to_dockerfile&gt;\r\nOR\r\n      image: &lt;name_of_image:version&gt;\r\n      enviroment:\r\n        - \"ConfVar:value\"\r\n        - \"homeDir:\/home\/dir\"\r\n      ports:\r\n        - \"[HostPort]:[ContainerPort]\"\r\n        - \"80:80\"\r\n      volumes:\r\n        - \/path\/container\/will\/use<\/pre>\n<figure class=\"gl gm gn go gp gq dc dd paragraph-image\">\n<div class=\"dc dd jv\">\n<div class=\"ha r gt hb\"><\/div>\n<\/div>\n<\/figure>\n<p id=\"5021\" class=\"hh hi dt ar hj b hk hl hm hn ho hp hq hr hs ht hu dl\" data-selectable-paragraph=\"\">Every <code class=\"hb ij ik il im b\">docker-compose<\/code> file will start with a minimum of <code class=\"hb ij ik il im b\">version: \"2\"<\/code>, if you\u2019re doing a Docker Swarm file it will need <code class=\"hb ij ik il im b\">version: \"3\"<\/code>, but for a single <code class=\"hb ij ik il im b\">docker-compose.yml<\/code>, you\u2019ll need v2.<\/p>\n<p data-selectable-paragraph=\"\"><a href=\"https:\/\/docs.docker.com\/storage\/volumes\/\">See here for more on the use of volumes<\/a><\/p>\n<p data-selectable-paragraph=\"\">I&#8217;m gonna keep this post short and use examples of these first two blogs it part 3. Where I setup and configure the first container in the BELK Stack; Elasticsearch.<\/p>\n<p data-selectable-paragraph=\"\">See you all at part 3! \ud83d\ude00<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Story Continues Following on from the last post, today we cover docker-compose to allow for easier deployment of docker images and configurations. As from my previous post you may want to indulge in the same reading I did here. Past those nice formalities, I find myself missing something&#8230; I&#8217;m not sure what it could &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/zewwy.ca\/index.php\/2020\/03\/16\/belk-stack-on-docker-part-2-docker-compose\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;BELK Stack on Docker <\/br>(Part 2 \u2013 Docker Compose)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"sfsi_plus_gutenberg_text_before_share":"","sfsi_plus_gutenberg_show_text_before_share":"","sfsi_plus_gutenberg_icon_type":"","sfsi_plus_gutenberg_icon_alignemt":"","sfsi_plus_gutenburg_max_per_row":"","footnotes":""},"categories":[8],"tags":[280,282,281],"class_list":["post-865","post","type-post","status-publish","format-standard","hentry","category-server-administration","tag-docker","tag-docker-compose","tag-elk"],"_links":{"self":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/comments?post=865"}],"version-history":[{"count":3,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/865\/revisions"}],"predecessor-version":[{"id":869,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/posts\/865\/revisions\/869"}],"wp:attachment":[{"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/media?parent=865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/categories?post=865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zewwy.ca\/index.php\/wp-json\/wp\/v2\/tags?post=865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}