{"id":1415,"date":"2019-10-15T17:36:27","date_gmt":"2019-10-15T12:06:27","guid":{"rendered":"https:\/\/opstree.com\/blog\/\/?p=1415"},"modified":"2019-10-15T17:36:27","modified_gmt":"2019-10-15T12:06:27","slug":"one-more-reason-to-use-docker","status":"publish","type":"post","link":"https:\/\/opstree.com\/blog\/2019\/10\/15\/one-more-reason-to-use-docker\/","title":{"rendered":"One more reason to use Docker"},"content":{"rendered":"\n<p>Recently I was working on a project which includes Terraform and AWS stuff. While working on that I was using my local machine for terraform code testing and luckily everything was going fine. But when we actually want to test it for the production environment we got some issues there. Then, as usual, we started to dig into the issue and finally, we got the issue which was quite a silly one \ud83d\ude1c. The production server Terraform version and my local development server Terraform version was not the same.&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/0*BkYDXNVAjm50ZZU_\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>After wasting quite a time on this issue, I decided to come up with a solution so this will never happen again.<\/p>\n\n\n\n<p>But before jumping to the solution, let\u2019s think is this problem was only related to Terraform or do we have faced the similar kind of issue in other scenarios as well.<\/p>\n\n\n\n<p>Well, I guess we face a similar kind of issue in other scenarios as well. Let\u2019s talk about some of the scenario\u2019s first.<\/p>\n\n\n\n<p>Suppose you have to create a CI pipeline for a project and that too with code re-usability. Now pipeline is ready and it is working fine in your project and then after some time, you have to implement the same kind of pipeline for the different project. Now you can use the same code but you don\u2019t know the exact version of tools which you were using with CI pipeline. This will lead you to error elevation.\u00a0<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1263\" height=\"315\" src=\"https:\/\/opstree.com\/blog\/\/wp-content\/uploads\/2019\/09\/screenshot-from-2019-09-24-17-18-14-2.png?w=1024\" alt=\"\" class=\"wp-image-1469\" \/><\/figure>\n\n\n\n<p>Let\u2019s take another example, suppose you are developing something in any of the programming languages. Surely that utility or program will have some dependencies as well. While installing those dependencies on the local system, it can corrupt your complete system or package manager for dependency management. A decent example is <strong>Pip <\/strong>which is a dependency manager of Python\ud83d\ude09.<\/p>\n\n\n\n<p>These are some example scenarios which we have faced actually and based on that we got the motivation for writing this blog.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Solution<\/h2>\n\n\n\n<p>To resolve all this problem we just need one thing i.e. <strong>containers<\/strong>. I can also say docker as well but container and docker are two different things.<\/p>\n\n\n\n<p>But yes for container management we use docker.<\/p>\n\n\n\n<p>So let\u2019s go back to our first problem the terraform one. If we have to solve that problem there are multiple ways to solve this. But we tried it to solve this using Docker.<\/p>\n\n\n\n<p>As Docker says<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Build Once and Run Anywhere<\/p><\/blockquote>\n\n\n\n<p>So based on this statement what we did, we created a Dockerfile for required Terraform version and stored it alongside with the code. Basically our Dockerfile looks like this:-<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">FROM alpine:3.8\n\nMAINTAINER OpsTree.com\n\nENV TERRAFORM_VERSION=0.11.10\n\nARG BASE_URL=https:\/\/releases.hashicorp.com\/terraform\n\nRUN apk add --no-cache curl unzip bash \\\n    &amp;&amp; curl -fsSL -o \/tmp\/terraform.zip ${BASE_URL}\/${TERRAFORM_VERSION}\/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \\\n    &amp;&amp; unzip \/tmp\/terraform.zip -d \/usr\/bin\/\n\nWORKDIR \/opstree\/terraform\n\nUSER opstree<\/pre>\n\n\n\n<p>In this Dockerfile, we are defining the version of Terraform which needs to run the code.<br>In a similar fashion, all other above listed problem can be solved using Docker. We just have to create a Dockerfile with exact dependencies which are needed and that same file can work in various environments and projects.<\/p>\n\n\n\n<p>To take it to the next level you can also dump a Makefile as well to make everyone life easier. For example:-<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">IMAGE_TAG=latest\nbuild-image:\n    docker build -t opstree\/terraform:${IMAGE_TAG} -f Dockerfile .\n\nrun-container:\n    docker run -itd --name terraform -v ~\/.ssh:\/root\/.ssh\/ -v ~\/.aws:\/root\/.aws -v ${PWD}:\/opstree\/terraform opstree\/terraform:${IMAGE_TAG}\n\nplan-infra:\n    docker exec -t terraform bash -c \"terraform plan\"\n\ncreate-infra:\n    docker exec -t terraform bash -c \"terraform apply -auto-approve\"\n\ndestroy-infra:\n    docker exec -t terraform bash -c \"terraform destroy -auto-approve\"<\/pre>\n\n\n\n<p>And trust me after making this utility available the reactions of the people who will be using this utility will be something like this:-<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"496\" height=\"258\" src=\"https:\/\/opstree.com\/blog\/\/wp-content\/uploads\/2019\/09\/tenor.gif?w=496\" alt=\"\" class=\"wp-image-1459\" \/><\/figure><\/div>\n\n\n\n<p>Now I am assuming you guys will also try to simulate the Docker in multiple scenarios as much as possible.<\/p>\n\n\n\n<p>There are a few more scenarios which yet to be explored to enhance the use of Docker if you find that before I do, please let me know.<\/p>\n\n\n\n<p>Thanks for reading, I\u2019d really appreciate any and all feedback, please leave your comment below if you guys have any feedback.<\/p>\n\n\n\n<p>Cheers till the next time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I was working on a project which includes Terraform and AWS stuff. While working on that I was using my local machine for terraform code testing and luckily everything was going fine. But when we actually want to test it for the production environment we got some issues there. Then, as usual, we started &hellip; <a href=\"https:\/\/opstree.com\/blog\/2019\/10\/15\/one-more-reason-to-use-docker\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;One more reason to use Docker&#8221;<\/span><\/a><\/p>\n","protected":false},"author":89038429,"featured_media":29900,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[27998418,182564,768739308,768739305,3021235],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2025\/11\/DevSecOps-1.jpg","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfDBOm-mP","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/1415"}],"collection":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/users\/89038429"}],"replies":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/comments?post=1415"}],"version-history":[{"count":22,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/1415\/revisions"}],"predecessor-version":[{"id":1577,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/1415\/revisions\/1577"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media\/29900"}],"wp:attachment":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media?parent=1415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/categories?post=1415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/tags?post=1415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}