{"id":193088,"date":"2021-03-03T16:00:32","date_gmt":"2021-03-03T13:00:32","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-connect-an-efs-volume-to-a-ecs-docker-container-cloudsavvy-it\/"},"modified":"2021-03-03T16:00:32","modified_gmt":"2021-03-03T13:00:32","slug":"how-to-connect-an-efs-volume-to-a-ecs-docker-container-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-connect-an-efs-volume-to-a-ecs-docker-container-cloudsavvy-it\/","title":{"rendered":"#How To Connect an EFS Volume to a ECS Docker Container \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a288b1ef3b00\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a288b1ef3b00\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-connect-an-efs-volume-to-a-ecs-docker-container-cloudsavvy-it\/#Why_Is_This_Useful\" >Why Is This Useful?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-connect-an-efs-volume-to-a-ecs-docker-container-cloudsavvy-it\/#Creating_an_EFS_Volume\" >Creating an EFS Volume<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-connect-an-efs-volume-to-a-ecs-docker-container-cloudsavvy-it\/#Connecting_To_an_ECS_Deployment\" >Connecting To an ECS Deployment<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How To Connect an EFS Volume to a ECS Docker Container \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<h3><img loading=\"lazy\" decoding=\"async\" class=\" alignnone wp-image-503 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/576bdb68675c300a17d82c131b23c927\/p\/uploads\/2019\/06\/c454d054.png\" alt=\"Docker logo.\" width=\"700\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/h3>\n<p>AWS\u2019s Elastic File System (EFS) is a shared storage drive that can be connected to many separate servers. It\u2019s a perfect pair with AWS\u2019s Elastic Container Service (ECS), which runs serverless Docker containers in cluster deployments, and can benefit from easy shared state.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Why_Is_This_Useful\"><\/span>Why Is This Useful?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>EFS is a fully managed storage service from Amazon. It\u2019s serverless, shared block storage that can be mounted to multiple servers. This makes it particularly useful in combination with Docker, which is usually stateless.<\/p>\n<p>For example, you could use this to host the static content and code for your website, then run all of your worker nodes on ECS to handle the actual serving of your content. This gets around the restriction of not storing data on disk, because the volume mount is bound to an external drive that persists across ECS deployments.<\/p>\n<p>While you can run Docker containers on ECS with local volumes, having a single, shared volume for the whole deployment can be a very useful tool for many deployments.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Creating_an_EFS_Volume\"><\/span>Creating an EFS Volume<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To set this up, you\u2019ll need to create an EFS file system. This is fairly straightforward, and can be done from the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/redirect.viglink.com?u=https%3A%2F%2Fconsole.aws.amazon.com%2Fefs%2Fhome&amp;key=204a528a336ede4177fff0d84a044482\">EFS Management Console<\/a>, but you\u2019ll want to make a note of the volume ID as you\u2019ll be needing it to work with the volume.<\/p>\n<p>Create a new file system:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9957 imgchk9\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/f9c6004aca330e63472d16380c047c2e\/p\/uploads\/2021\/03\/f70c0e66.png\" alt=\"\" width=\"461\" height=\"192\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Enter a name, then choose the VPC where your ECS cluster is located.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9958 imgchk9\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/92688149328b8f5fb7b8191de4c55f16\/p\/uploads\/2021\/03\/2437f5b1.png\" alt=\"\" width=\"632\" height=\"408\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Then, you can make a note of the File System ID, as you\u2019ll need it later.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9959 imgchk9\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/f058fca7188403dba0326ba65368fde2\/p\/uploads\/2021\/03\/2a14466b.png\" alt=\"\" width=\"700\" height=\"243\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you need to preload data on this filesystem, or just manually add or change files in your EFS volume, you can mount it to any EC2 instance. You\u2019ll need to install <code>amazon-efs-utils<\/code>:<\/p>\n<pre>sudo yum install -y amazon-efs-utils<\/pre>\n<p>And then mount it with the following command, using the ID:<\/p>\n<pre>sudo mount -t efs fs-12345678:\/ \/mnt\/efs<\/pre>\n<p>This way, you can directly view and edit the contents of your EFS volume as if it was another HDD on your server. You\u2019ll want to make sure you have <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/redirect.viglink.com?u=https%3A%2F%2Fdocs.aws.amazon.com%2Fefs%2Flatest%2Fug%2Fwt1-test.html%23wt1-connect-install-nfs-client&amp;key=204a528a336ede4177fff0d84a044482\">nfs-utils<\/a> installed for this all to work properly.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Connecting_To_an_ECS_Deployment\"><\/span>Connecting To an ECS Deployment<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Next, you\u2019ll have to hook up ECS to this volume. Create a new task definition in the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/redirect.viglink.com?u=https%3A%2F%2Fconsole.aws.amazon.com%2Fecs%2Fhome&amp;key=204a528a336ede4177fff0d84a044482\">ECS Management Console<\/a>. Scroll to the bottom, and select \u201cConfigure Via JSON.\u201d Then, replace the empty \u201cvolumes\u201d key with the following JSON, adding the \u201cfamily\u201d key at the end:<\/p>\n<pre>\"volumes\": [&#13;\n        {&#13;\n            \"name\": \"efs-demo\",&#13;\n            \"host\": null,&#13;\n            \"dockerVolumeConfiguration\": {&#13;\n                \"autoprovision\": true,&#13;\n                \"labels\": null,&#13;\n                \"scope\": \"shared\",&#13;\n                \"driver\": \"local\",&#13;\n                \"driverOpts\": {&#13;\n                    \"type\": \"nfs\",&#13;\n                    \"device\": \":\/\",&#13;\n                    \"o\": \"addr=fs-XXXXXX.efs.us-east-1.amazonaws.com,nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport\"&#13;\n                }&#13;\n            }&#13;\n        }&#13;\n    ],&#13;\n\"family\":\"nginx\",<\/pre>\n<p>Of course, you will need to replace <code>fs-XXXXXX.efs.us-east-1.amazonaws.com<\/code>\u00a0with your EFS volume\u2019s actual address. You should see a new volume:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3631\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/a6f15ab233d7dc335bff4d669ffe53a2\/p\/uploads\/2020\/01\/d6b5ab83.png\" alt=\"ecs new volume\" width=\"700\" height=\"392\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can use this in your container definition as a mount point. Select \u201cAdd Container\u201d (or edit an existing one), and under \u201cStorage And Logging,\u201d select the newly created volume and specify a container path.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3632\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/837ae03d6603a7dfb611d24f81132972\/p\/uploads\/2020\/01\/d6b5ab83-1.png\" alt=\"add mount point\" width=\"700\" height=\"260\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Save the task definition, and when you launch a cluster with this new definition, all of the containers will be able to access your shared file system.\n<\/p><\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/7558\/how-to-connect-an-efs-volume-to-a-ecs-docker-container\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How To Connect an EFS Volume to a ECS Docker Container \u2013 CloudSavvy IT&#8221; AWS\u2019s Elastic File System (EFS) is a shared storage drive that can be connected to many separate servers. It\u2019s a perfect pair with AWS\u2019s Elastic Container Service (ECS), which runs serverless Docker containers in cluster deployments, and can benefit from easy&#8230;<\/p>\n","protected":false},"author":1,"featured_media":193089,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/576bdb68675c300a17d82c131b23c927\/p\/uploads\/2019\/06\/c454d054.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-193088","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/193088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=193088"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/193088\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/193089"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=193088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=193088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=193088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}