{"id":9419,"date":"2022-05-12T15:13:02","date_gmt":"2022-05-12T09:43:02","guid":{"rendered":"https:\/\/www.skynats.com\/?p=9419"},"modified":"2024-02-21T19:12:22","modified_gmt":"2024-02-21T13:42:22","slug":"aws-opsworks-docker-an-overview","status":"publish","type":"post","link":"https:\/\/www.skynats.com\/blog\/aws-opsworks-docker-an-overview\/","title":{"rendered":"AWS OpsWorks Docker | An Overview"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is AWS OpsWorks Docker?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">AWS OpsWorks enables us to deploy and manage various applications. We can also create instances for EC2 instances to install and configure any software we need. We can use templates or create our own by using Chef recipes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These templates enable us to install software packages and carry out any scripted task. AWS OpsWorks can also scale our application using application load-based or time-based scaling. It also keeps the application healthy by monitoring for failed instances and replacing them as needed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are a few benefits of using Docker on AWS OpsWorks.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>AWS resource automation<\/li><li>Docker version and installation are completely under your control.<\/li><li>Resource discovery<\/li><li>Complete control over container-to-instance mapping<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-run-docker-on-aws-opsworks\">How to run Docker on AWS OpsWorks?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The steps involved in the AWS OpsWorks Docker process:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Make recipes<\/li><li>Make an OpsWorks Stack.<\/li><li>Create a layer<\/li><li>Include an instance<\/li><li>Add an app and then deploy it.<\/li><li>Create attributes dynamic<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how-to-make-recipes-on-aws-opsworks\">How to Make Recipes on AWS OpsWorks?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To begin, make a repository to keep the Chef recipes. The following docker:: The install recipe installs the necessary Docker software on AWS OpsWorks :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>case node&#91;:platform]\nwhen \"ubuntu\",\"debian\"\n  package \"docker.io\" do\n    action :install\n  end\nwhen 'centos','redhat','fedora','amazon'\n  package \"docker\" do\n    action :install\n  end\nend\n\nservice \"docker\" do\n  action :start\nend<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Furthermore, the docker::docker-deploy recipe below deploys the docker containers on AWS OpsWorks:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_recipe 'deploy'\n\nnode&#91;:deploy].each do |application, deploy|\n  \n  if node&#91;:opsworks]&#91;:instance]&#91;:layers].first != deploy&#91;:environment_variables]&#91;:layer]\n    Chef::Log.debug(\"Skipping deploy::docker application #{application} as it is not deployed to this layer\")\n    next\n  end\n\n  opsworks_deploy_dir do\n    user deploy&#91;:user]\n    group deploy&#91;:group]\n    path deploy&#91;:deploy_to]\n  end\n\n  opsworks_deploy do\n    deploy_data deploy\n    app application\n  end\n\n  bash \"docker-cleanup\" do\n    user \"root\"\n    code &lt;&lt;-EOH\n      if docker ps | grep #{deploy&#91;:application]}; \n      then\n        docker stop #{deploy&#91;:application]}\n        sleep 3\n        docker rm #{deploy&#91;:application]}\n        sleep 3\n      fi\n      if docker images | grep #{deploy&#91;:application]}; \n      then\n        docker rmi #{deploy&#91;:application]}\n      fi\n    EOH\n  end\n\n  bash \"docker-build\" do\n    user \"root\"\n    cwd \"#{deploy&#91;:deploy_to]}\/current\"\n    code &lt;&lt;-EOH\n     docker build -t=#{deploy&#91;:application]} . &gt; #{deploy&#91;:application]}-docker.out\n    EOH\n  end\n  \n  dockerenvs = \" \"\n  deploy&#91;:environment_variables].each do |key, value|\n    dockerenvs=dockerenvs+\" -e \"+key+\"=\"+value\n  end\n  \n  bash \"docker-run\" do\n    user \"root\"\n    cwd \"#{deploy&#91;:deploy_to]}\/current\"\n    code &lt;&lt;-EOH\n      docker run #{dockerenvs} -p #{node&#91;:opsworks]&#91;:instance]&#91;:private_ip]}:#{deploy&#91;:environment_variables]&#91;:service_port]}:#{deploy&#91;:environment_variables]&#91;:container_port]} --name #{deploy&#91;:application]} -d #{deploy&#91;:application]}\n    EOH\n  end\n\nend<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Following that, we must create a repository to store the Dockerfile.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-how-to-create-an-opsworks-stack\">How to Create an OpsWorks Stack?<\/h4>\n\n\n\n<ol class=\"wp-block-list\"><li>To begin, launch the AWS OpsWorks console.<\/li><li>After that, choose Add a Stack and Advanced.<\/li><li>Set the Use custom Chef Cookbooks option to Yes and the Repository type to Git.<\/li><li>Afterward, set the Repository URL to the repository where we saved the recipes from the previous step.<\/li><\/ol>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-how-to-create-a-layer\">How to Create a Layer?<\/h4>\n\n\n\n<ol class=\"wp-block-list\"><li>Select Add Layer from the AWS OpsWorks console.<\/li><li>Then, select Custom Layer, enter &#8220;Docker&#8221; as the name and &#8220;docker&#8221; as the shortname, and click Add Layer.<\/li><li>Next, go to the Custom Chef recipes section by selecting the layer&#8217;s Edit Recipes action.<\/li><li>Then, in the Setup box, type docker::install and in the Deploy box, docker::docker-deploy, and click +.<\/li><li>Finally, click the Save button to finish.<\/li><\/ol>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-how-to-include-an-instance\">How to Include an Instance?<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">At this point, the Layer page on AWS OpsWorks will show the Docker layer. We must now add instances to the layer by choosing Instances from the Docker layer and clicking the + button. Accept the default settings and then click the Add Instance button. To begin the instance, we must choose Start from the row&#8217;s actions column. This starts a new EC2 instance and also executes the Setup recipes to configure Docker.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After launching the instance, we must add an app and deploy it. This is accomplished through the AWS OpsWorks console. We will be able to see the app after it has been deployed by clicking the server&#8217;s public IP address. To finish the process, we must update AWS OpsWorks attributes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you need assistance setting up AWS OpsWorks Docker, our <a href=\"https:\/\/www.skynats.com\/aws-management\/\" target=\"_blank\" rel=\"noreferrer noopener\">AWS Support<\/a> Teams are available to assist you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is AWS OpsWorks Docker? AWS OpsWorks enables us to deploy and manage various applications. We can also create instances for EC2 instances to install and configure any software we need. We can use templates or create our own by using Chef recipes. These templates enable us to install software packages and carry out any [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,142],"tags":[696],"class_list":["post-9419","post","type-post","status-publish","format-standard","hentry","category-blog","category-aws-management","tag-aws-opsworks-docker"],"_links":{"self":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/9419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/comments?post=9419"}],"version-history":[{"count":0,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/9419\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/media?parent=9419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/categories?post=9419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/tags?post=9419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}