

{"id":37756,"date":"2018-11-27T16:00:43","date_gmt":"2018-11-27T10:30:43","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=37756"},"modified":"2018-11-27T16:00:43","modified_gmt":"2018-11-27T10:30:43","slug":"docker-compose","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/docker-compose\/","title":{"rendered":"Docker Compose Tutorial &#8211; Process, Feature, and Use Cases"},"content":{"rendered":"<p><span style=\"font-weight: 400\">Today, we will see Docker Compose Tutorial. Moreover, we will look at Docker Compose features and use cases. Also, we will see Compose Versions, Build and installation. Along with this, we will <strong>discuss the Docker<\/strong> Compose examples.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><em> In order to define and run multi-container Docker applications, there is a tool we have, that tool is what we call Docker Compose.\u00a0<\/em><\/span><\/p>\n<p>So, let&#8217;s begin Docker Compose Tutorial.<\/p>\n<h2>What is Docker Compose?<\/h2>\n<p><span style=\"font-weight: 400\">While our Docker application includes more than one container, at that time building, running, as well as connecting the containers from separate Dockerfiles is definitely time-consuming. So, as a solution to this problem, Docker Compose permits us to use a YAML file to define multi-container apps. <\/span><\/p>\n<p><span style=\"font-weight: 400\">It is possible to configure as many containers as we want, how they should be built and connected, and where data should be stored. We can run a single command to build, run, and configure all of the containers when the YAML file is complete.<\/span><\/p>\n<p><span style=\"font-weight: 400\">In addition, Compose works in several environments like staging, production, testing, development, as well as CI workflows. <\/span><\/p>\n<h2><span style=\"font-weight: 400\">How to Use Docker Compose?<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Basically, using Compose in Docker is a three-step process:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">At very first, define app\u2019s environment with a Dockerfile hence we can reproduce it anywhere.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Afterwards, define the services that make up the app in docker-compose.yml hence it can be run together in an isolated environment.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Further, run docker-compose up and Compose starts and then it runs the entire app.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">Below you can see, how a docker-compose.yml looks like:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">version: '3'\nservices:\n\u00a0web:\n\u00a0\u00a0\u00a0build: .\n\u00a0\u00a0\u00a0ports:\n\u00a0\u00a0\u00a0- \"5000:5000\"\n\u00a0\u00a0\u00a0volumes:\n\u00a0\u00a0\u00a0- .:\/code\n\u00a0\u00a0\u00a0- logvolume01:\/var\/log\n\u00a0\u00a0\u00a0links:\n\u00a0\u00a0\u00a0- redis\n\u00a0redis:\n\u00a0\u00a0\u00a0image: redis\nvolumes:\n\u00a0logvolume01: {}<\/pre>\n<h2>Docker Compose Command<\/h2>\n<p><span style=\"font-weight: 400\">In order to manage the whole lifecycle of the application, Docker Compose has several commands:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400\">Start, stop, and rebuild services<\/span><\/li>\n<li><span style=\"font-weight: 400\">View the status of running services<\/span><\/li>\n<li><span style=\"font-weight: 400\">Stream the log output of running services<\/span><\/li>\n<li><span style=\"font-weight: 400\">Run a one-off command on a service<\/span><\/li>\n<\/ul>\n<h2>Features of Docker Compose<\/h2>\n<p><span style=\"font-weight: 400\">There are some features of Compose in Docker which makes it effective, such as:<\/span><\/p>\n<ol>\n<li><span style=\"font-weight: 400\"> Multiple isolated environments on a single host<\/span><\/li>\n<li><span style=\"font-weight: 400\"> Preserve volume data when containers are created<\/span><\/li>\n<li><span style=\"font-weight: 400\"> Only recreate containers that have changed<\/span><\/li>\n<li><span style=\"font-weight: 400\"> Variables and moving a composition between environments<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400\">Let\u2019s learn all these features in brief:<\/span><\/p>\n<h3><span style=\"font-weight: 400\">i. Multiple isolated environments on a single host<\/span><\/h3>\n<p><span style=\"font-weight: 400\">In order to isolate environments from each other, Compose uses a project name. We can make use of this project name in various different contexts, like:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400\">On a dev host, in order to create multiple copies of a single environment, like while we want to run a stable copy for each feature branch of a project.<\/span><\/li>\n<li><span style=\"font-weight: 400\">Moreover, on a CI server, in order to keep builds from interfering with each other, we can set the project name to a unique build number.<\/span><\/li>\n<li><span style=\"font-weight: 400\">And, on a shared host or dev host, in order to prevent different projects, that may use the same service names, from interfering with each other.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">Here, the default project name is the basename of the project directory. However, by using the -p command line option or the COMPOSE_PROJECT_NAME environment variable, we can set a custom project name.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">ii. Preserve volume data when containers are created<\/span><\/h3>\n<p><span style=\"font-weight: 400\">All volumes used by our services is preserved by Compose. When docker-compose up runs, it copies the volumes from the old container to the new container, if it finds any containers from previous runs. As its best feature, this process ensures that any data we\u2019ve created in volumes isn\u2019t lost.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">iii. Only recreate containers that have changed<\/span><\/h3>\n<p><span style=\"font-weight: 400\">In order to create a container, Compose caches the configuration used. Moreover, Compose re-uses the existing containers, when we restart a service that has not changed. Here, Re-using containers, simply means that we can make changes to our environment very quickly.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">iv. Variables and moving a composition between environments<\/span><\/h3>\n<p><span style=\"font-weight: 400\">In the Compose file, Compose supports variables. Basically, to customize our composition for different environments or different users, \u00a0we can use these variables. <\/span><\/p>\n<p><span style=\"font-weight: 400\">In addition, by using the extends field or by creating multiple Compose files, we can extend a Compose file.<\/span><\/p>\n<h2><span style=\"font-weight: 400\">Docker Compose Use Cases<\/span><\/h2>\n<p><span style=\"font-weight: 400\">In many different ways, we can use Compose. So, here we are listing some \u00a0of the common use cases of Docker Compose:<\/span><\/p>\n<h3><span style=\"font-weight: 400\">i. Development Environments<\/span><\/h3>\n<p><span style=\"font-weight: 400\">While we are developing software, the ability to run an application in an isolated environment as well as interact with it is very crucial. So, in order to create the environment and interact with it, we can use the Compose command line tool.<\/span><\/p>\n<p><span style=\"font-weight: 400\">In addition, to document and configure all of the application\u2019s service dependencies (databases, queues, caches, web service APIs, etc), the Compose file offers a way. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Moreover, we can create and start one or more containers for each dependency with a single command (docker-compose up), by using the Compose command line tool.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Furthermore, these features together offer a convenient way for developers to get started on a project. <\/span><\/p>\n<h3><span style=\"font-weight: 400\">ii. Automated Testing Environments<\/span><\/h3>\n<p><span style=\"font-weight: 400\">The automated test suite is an important part of any Continuous Deployment or Continuous Integration process. However, Automated end-to-end testing needs an environment in which to run tests. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Yet, \u00a0to create and destroy isolated testing environments for our test suite, Compose offers a convenient way. And, we can create and destroy these environments in just a few commands, by defining the full environment in a Compose file:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">$ docker-compose up -d\n$ .\/run_tests\n$ docker-compose down<\/pre>\n<h3><span style=\"font-weight: 400\">iii. Single Host Deployments<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Well, traditionally, Compose has been focused on the development and testing workflows. Although, we\u2019re making progress on more production-oriented features, with each release. In order to deploy to a remote Docker Engine, we can use Compose. <\/span><\/p>\n<p><span style=\"font-weight: 400\">However, the Docker Engine may be a single instance provisioned either with Docker Machine or an entire Docker Swarm cluster.<\/span><\/p>\n<p>So, this was in Docker Compose Tutorial. Hope you like our explanation.<\/p>\n<h2><span style=\"font-weight: 400\">Conclusion<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Hence, we have seen the concept of Docker Compose in detail. Also, we discussed its features as well as use cases for better understanding. Though, if any doubt occurs, feel free to ask through the comment tab. We are happy to help. Keep visiting, keep learning!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we will see Docker Compose Tutorial. Moreover, we will look at Docker Compose features and use cases. Also, we will see Compose Versions, Build and installation. Along with this, we will discuss the&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":37790,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16988],"tags":[17045,17049,17047,17052,17046,17048,17050,6759,17051],"class_list":["post-37756","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker","tag-docker-compose","tag-docker-compose-build","tag-docker-compose-examples","tag-docker-compose-features","tag-docker-compose-tutorial","tag-docker-compose-versions","tag-how-to-use-docker-compose","tag-install-docker-compose","tag-what-is-docker-compose"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Docker Compose Tutorial - Process, Feature, and Use Cases - DataFlair<\/title>\n<meta name=\"description\" content=\"Docker Compose Tutorial - what is compose in docker, how to use compose, Compose Versions, Compose Build, Compose Features, Example of 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:\/\/data-flair.training\/blogs\/docker-compose\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Docker Compose Tutorial - Process, Feature, and Use Cases - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Docker Compose Tutorial - what is compose in docker, how to use compose, Compose Versions, Compose Build, Compose Features, Example of Compose\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/docker-compose\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-11-27T10:30:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/10\/Docker-Compose-Tutorial-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1202\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Docker Compose Tutorial - Process, Feature, and Use Cases - DataFlair","description":"Docker Compose Tutorial - what is compose in docker, how to use compose, Compose Versions, Compose Build, Compose Features, Example of 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:\/\/data-flair.training\/blogs\/docker-compose\/","og_locale":"en_US","og_type":"article","og_title":"Docker Compose Tutorial - Process, Feature, and Use Cases - DataFlair","og_description":"Docker Compose Tutorial - what is compose in docker, how to use compose, Compose Versions, Compose Build, Compose Features, Example of Compose","og_url":"https:\/\/data-flair.training\/blogs\/docker-compose\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-11-27T10:30:43+00:00","og_image":[{"width":1202,"height":630,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/10\/Docker-Compose-Tutorial-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/docker-compose\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/docker-compose\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Docker Compose Tutorial &#8211; Process, Feature, and Use Cases","datePublished":"2018-11-27T10:30:43+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/docker-compose\/"},"wordCount":999,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/docker-compose\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/10\/Docker-Compose-Tutorial-01.jpg","keywords":["docker compose","Docker Compose Build","Docker Compose Examples","Docker Compose Features","Docker Compose Tutorial","Docker Compose Versions","how to use docker compose","Install Docker Compose","what is docker compose"],"articleSection":["Docker Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/docker-compose\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/docker-compose\/","url":"https:\/\/data-flair.training\/blogs\/docker-compose\/","name":"Docker Compose Tutorial - Process, Feature, and Use Cases - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/docker-compose\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/docker-compose\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/10\/Docker-Compose-Tutorial-01.jpg","datePublished":"2018-11-27T10:30:43+00:00","description":"Docker Compose Tutorial - what is compose in docker, how to use compose, Compose Versions, Compose Build, Compose Features, Example of Compose","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/docker-compose\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/docker-compose\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/docker-compose\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/10\/Docker-Compose-Tutorial-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/10\/Docker-Compose-Tutorial-01.jpg","width":1202,"height":630,"caption":"Docker Compose Tutorial - Process, Feature, and Use Cases"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/docker-compose\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Docker Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/docker\/"},{"@type":"ListItem","position":3,"name":"Docker Compose Tutorial &#8211; Process, Feature, and Use Cases"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/37756","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=37756"}],"version-history":[{"count":0,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/37756\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/37790"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=37756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=37756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=37756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}