{"id":1861,"date":"2022-02-14T15:01:05","date_gmt":"2022-02-14T15:01:05","guid":{"rendered":"https:\/\/takeondevops.com\/?p=1861"},"modified":"2022-02-14T15:01:09","modified_gmt":"2022-02-14T15:01:09","slug":"running-containers-docker-compose","status":"publish","type":"post","link":"https:\/\/takeondevops.com\/?p=1861","title":{"rendered":"Running containers with docker-compose"},"content":{"rendered":"\n<p>As promised in the previous post <a href=\"https:\/\/takeondevops.com\/?p=1856\">here<\/a>, today we will go over running containers with docker-compose. We will use the same source code(react covid dashboard) as in the last post. So, if you want to follow along you can use the same. <\/p>\n\n\n\n<p>Below is the docker-compose.yml file from the repo.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>---\nversion:  \"3.7\"\n\nservices:\n  covid-app:\n    tty:  true\n    image:  node:12-alpine\n    command:  sh -c \"rm -rf node_module &amp;&amp; rm -f yarn.lock &amp;&amp; npm install node-sass@4.13 &amp;&amp; npm install &amp;&amp; npm start\"\n    ports:\n      - 80:3000\n    working_dir:  \/app\n    volumes:\n      - .\/:\/app<\/code><\/pre>\n\n\n\n<p>Unfortunately, I couldn&#8217;t get this to run with yarn as yet. Running the simple Dockerfile in the previous case was challenging because there were errors that didn&#8217;t show up when run locally or on Heroku. While we&#8217;re at it, if you need to know how to run this dashboard locally or in Heroku, then check <a href=\"https:\/\/takeondevops.com\/?p=325\">this post<\/a>. So, as I was saying, Dockerfile was challenging but I managed to get it to work with yarn(and vanilla node). But on this case, it was taking too long to find a fix for yarn. Since my main goal is to demonstrate on how docker-compose works, I just made sure it works with vanilla node.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"why-docker-compose\">Why docker-compose?<\/h3>\n\n\n\n<p>So let&#8217;s just cut to the chase. If it works in Dockerfile, then why bother? The answer to that is, 4 things.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>You can run multiple containers and is good for starting multi-container environments.<\/li><li>The application run using the containers, can be started using a single command.<\/li><li>You can leverage the Dockerfile to build the images. (Not covered here.)<\/li><li>Can make instant live changes to the containers.<\/li><\/ol>\n\n\n\n<p>Now let&#8217;s go in to the details of the above 3 points. Regarding the first point, under the services section in the YAML file, we only see one container named covid-app. But there can be more as required. In our case we only have one. About the second point we can start all the containers using a single command. The command is <code>docker-compose up -d<\/code> . This command will build and run the containers. Here, in case we need to maintain a sequence as to what container needs to be up first before another one could start, we can use the <code>depends_on<\/code> section to do so. About the 3rd point, we can simply add a <code>build<\/code> section to the above YAML to re-purpose the Dockerfile and build based on that.<\/p>\n\n\n\n<p>You might have noticed that we are using volumes in docker-compose. (Which we didn&#8217;t use in Dockerfile as we just copied over the contents to the contianer.) That is one key difference between docker-compose and Dockerfile. Since we have a volume and our application code which is available locally( on our hosts&#8217; hard drive) has been mounted in to the container as a volume, the changes we make on the code locally, results in changes in the containers instantly. This can be an advantage and a disadvantage as well.<\/p>\n\n\n\n<p>That&#8217;s all for this post. Catch you all next time with another post \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As promised in the previous post here, today we will go over running containers with docker-compose. We will use the same source code(react covid dashboard) as in the last post. So, if you want to follow along you can use the same. Below is the docker-compose.yml file from the repo. Unfortunately, I couldn&#8217;t get this [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[3,4,6,7,1],"tags":[],"class_list":["post-1861","post","type-post","status-publish","format-standard","hentry","category-dev","category-featured","category-network","category-systems","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Running containers with docker-compose - Take On Devops<\/title>\n<meta name=\"description\" content=\"This is a continuation of the last blog on Dockerfile. Here, we are looking at building and running containers using docker-compose.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/takeondevops.com\/?p=1861\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Running containers with docker-compose - Take On Devops\" \/>\n<meta property=\"og:description\" content=\"This is a continuation of the last blog on Dockerfile. Here, we are looking at building and running containers using docker-compose.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/takeondevops.com\/?p=1861\" \/>\n<meta property=\"og:site_name\" content=\"Take On Devops\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-14T15:01:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-14T15:01:09+00:00\" \/>\n<meta name=\"author\" content=\"ihsan izwer\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ihsan izwer\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/takeondevops.com\\\/?p=1861#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/takeondevops.com\\\/?p=1861\"},\"author\":{\"name\":\"ihsan izwer\",\"@id\":\"https:\\\/\\\/takeondevops.com\\\/#\\\/schema\\\/person\\\/465f2fb632235eb4079002754cd66aeb\"},\"headline\":\"Running containers with docker-compose\",\"datePublished\":\"2022-02-14T15:01:05+00:00\",\"dateModified\":\"2022-02-14T15:01:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/takeondevops.com\\\/?p=1861\"},\"wordCount\":462,\"articleSection\":[\"Dev\",\"Featured\",\"Network\",\"Systems\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/takeondevops.com\\\/?p=1861\",\"url\":\"https:\\\/\\\/takeondevops.com\\\/?p=1861\",\"name\":\"Running containers with docker-compose - Take On Devops\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/takeondevops.com\\\/#website\"},\"datePublished\":\"2022-02-14T15:01:05+00:00\",\"dateModified\":\"2022-02-14T15:01:09+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/takeondevops.com\\\/#\\\/schema\\\/person\\\/465f2fb632235eb4079002754cd66aeb\"},\"description\":\"This is a continuation of the last blog on Dockerfile. Here, we are looking at building and running containers using docker-compose.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/takeondevops.com\\\/?p=1861#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/takeondevops.com\\\/?p=1861\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/takeondevops.com\\\/?p=1861#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/takeondevops.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Running containers with docker-compose\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/takeondevops.com\\\/#website\",\"url\":\"https:\\\/\\\/takeondevops.com\\\/\",\"name\":\"Take On Devops\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/takeondevops.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/takeondevops.com\\\/#\\\/schema\\\/person\\\/465f2fb632235eb4079002754cd66aeb\",\"name\":\"ihsan izwer\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c82c3d13c92d77259746074978cb7d498778b44914dea60ad0367dec237c349f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c82c3d13c92d77259746074978cb7d498778b44914dea60ad0367dec237c349f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c82c3d13c92d77259746074978cb7d498778b44914dea60ad0367dec237c349f?s=96&d=mm&r=g\",\"caption\":\"ihsan izwer\"},\"url\":\"https:\\\/\\\/takeondevops.com\\\/?author=3\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Running containers with docker-compose - Take On Devops","description":"This is a continuation of the last blog on Dockerfile. Here, we are looking at building and running containers using docker-compose.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/takeondevops.com\/?p=1861","og_locale":"en_US","og_type":"article","og_title":"Running containers with docker-compose - Take On Devops","og_description":"This is a continuation of the last blog on Dockerfile. Here, we are looking at building and running containers using docker-compose.","og_url":"https:\/\/takeondevops.com\/?p=1861","og_site_name":"Take On Devops","article_published_time":"2022-02-14T15:01:05+00:00","article_modified_time":"2022-02-14T15:01:09+00:00","author":"ihsan izwer","twitter_card":"summary_large_image","twitter_misc":{"Written by":"ihsan izwer","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/takeondevops.com\/?p=1861#article","isPartOf":{"@id":"https:\/\/takeondevops.com\/?p=1861"},"author":{"name":"ihsan izwer","@id":"https:\/\/takeondevops.com\/#\/schema\/person\/465f2fb632235eb4079002754cd66aeb"},"headline":"Running containers with docker-compose","datePublished":"2022-02-14T15:01:05+00:00","dateModified":"2022-02-14T15:01:09+00:00","mainEntityOfPage":{"@id":"https:\/\/takeondevops.com\/?p=1861"},"wordCount":462,"articleSection":["Dev","Featured","Network","Systems"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/takeondevops.com\/?p=1861","url":"https:\/\/takeondevops.com\/?p=1861","name":"Running containers with docker-compose - Take On Devops","isPartOf":{"@id":"https:\/\/takeondevops.com\/#website"},"datePublished":"2022-02-14T15:01:05+00:00","dateModified":"2022-02-14T15:01:09+00:00","author":{"@id":"https:\/\/takeondevops.com\/#\/schema\/person\/465f2fb632235eb4079002754cd66aeb"},"description":"This is a continuation of the last blog on Dockerfile. Here, we are looking at building and running containers using docker-compose.","breadcrumb":{"@id":"https:\/\/takeondevops.com\/?p=1861#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/takeondevops.com\/?p=1861"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/takeondevops.com\/?p=1861#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/takeondevops.com\/"},{"@type":"ListItem","position":2,"name":"Running containers with docker-compose"}]},{"@type":"WebSite","@id":"https:\/\/takeondevops.com\/#website","url":"https:\/\/takeondevops.com\/","name":"Take On Devops","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/takeondevops.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/takeondevops.com\/#\/schema\/person\/465f2fb632235eb4079002754cd66aeb","name":"ihsan izwer","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c82c3d13c92d77259746074978cb7d498778b44914dea60ad0367dec237c349f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c82c3d13c92d77259746074978cb7d498778b44914dea60ad0367dec237c349f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c82c3d13c92d77259746074978cb7d498778b44914dea60ad0367dec237c349f?s=96&d=mm&r=g","caption":"ihsan izwer"},"url":"https:\/\/takeondevops.com\/?author=3"}]}},"jetpack_featured_media_url":"","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/takeondevops.com\/index.php?rest_route=\/wp\/v2\/posts\/1861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/takeondevops.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/takeondevops.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/takeondevops.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/takeondevops.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1861"}],"version-history":[{"count":2,"href":"https:\/\/takeondevops.com\/index.php?rest_route=\/wp\/v2\/posts\/1861\/revisions"}],"predecessor-version":[{"id":1863,"href":"https:\/\/takeondevops.com\/index.php?rest_route=\/wp\/v2\/posts\/1861\/revisions\/1863"}],"wp:attachment":[{"href":"https:\/\/takeondevops.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/takeondevops.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/takeondevops.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}