Need Assistance?

In only two hours, with an average response time of 15 minutes, our expert will have your problem sorted out.

Server Trouble?

For a single, all-inclusive fee, we guarantee the continuous reliability, safety, and blazing speed of your servers.

AWS OpsWorks Docker | An Overview

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 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.

Here are a few benefits of using Docker on AWS OpsWorks.

  • AWS resource automation
  • Docker version and installation are completely under your control.
  • Resource discovery
  • Complete control over container-to-instance mapping

How to run Docker on AWS OpsWorks?

The steps involved in the AWS OpsWorks Docker process:

  • Make recipes
  • Make an OpsWorks Stack.
  • Create a layer
  • Include an instance
  • Add an app and then deploy it.
  • Create attributes dynamic

How to Make Recipes on AWS OpsWorks?

To begin, make a repository to keep the Chef recipes. The following docker:: The install recipe installs the necessary Docker software on AWS OpsWorks :

case node[:platform]
when "ubuntu","debian"
  package "docker.io" do
    action :install
  end
when 'centos','redhat','fedora','amazon'
  package "docker" do
    action :install
  end
end

service "docker" do
  action :start
end

Furthermore, the docker::docker-deploy recipe below deploys the docker containers on AWS OpsWorks:

include_recipe 'deploy'

node[:deploy].each do |application, deploy|
  
  if node[:opsworks][:instance][:layers].first != deploy[:environment_variables][:layer]
    Chef::Log.debug("Skipping deploy::docker application #{application} as it is not deployed to this layer")
    next
  end

  opsworks_deploy_dir do
    user deploy[:user]
    group deploy[:group]
    path deploy[:deploy_to]
  end

  opsworks_deploy do
    deploy_data deploy
    app application
  end

  bash "docker-cleanup" do
    user "root"
    code <<-EOH
      if docker ps | grep #{deploy[:application]}; 
      then
        docker stop #{deploy[:application]}
        sleep 3
        docker rm #{deploy[:application]}
        sleep 3
      fi
      if docker images | grep #{deploy[:application]}; 
      then
        docker rmi #{deploy[:application]}
      fi
    EOH
  end

  bash "docker-build" do
    user "root"
    cwd "#{deploy[:deploy_to]}/current"
    code <<-EOH
     docker build -t=#{deploy[:application]} . > #{deploy[:application]}-docker.out
    EOH
  end
  
  dockerenvs = " "
  deploy[:environment_variables].each do |key, value|
    dockerenvs=dockerenvs+" -e "+key+"="+value
  end
  
  bash "docker-run" do
    user "root"
    cwd "#{deploy[:deploy_to]}/current"
    code <<-EOH
      docker run #{dockerenvs} -p #{node[:opsworks][:instance][:private_ip]}:#{deploy[:environment_variables][:service_port]}:#{deploy[:environment_variables][:container_port]} --name #{deploy[:application]} -d #{deploy[:application]}
    EOH
  end

end

Following that, we must create a repository to store the Dockerfile.

How to Create an OpsWorks Stack?

  1. To begin, launch the AWS OpsWorks console.
  2. After that, choose Add a Stack and Advanced.
  3. Set the Use custom Chef Cookbooks option to Yes and the Repository type to Git.
  4. Afterward, set the Repository URL to the repository where we saved the recipes from the previous step.

How to Create a Layer?

  1. Select Add Layer from the AWS OpsWorks console.
  2. Then, select Custom Layer, enter “Docker” as the name and “docker” as the shortname, and click Add Layer.
  3. Next, go to the Custom Chef recipes section by selecting the layer’s Edit Recipes action.
  4. Then, in the Setup box, type docker::install and in the Deploy box, docker::docker-deploy, and click +.
  5. Finally, click the Save button to finish.

How to Include an Instance?

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’s actions column. This starts a new EC2 instance and also executes the Setup recipes to configure Docker.

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’s public IP address. To finish the process, we must update AWS OpsWorks attributes.

If you need assistance setting up AWS OpsWorks Docker, our AWS Support Teams are available to assist you.

Liked!! Share the post.

Get Support right now!

Start server management with our 24x7 monitoring and active support team

Can't get what you are looking for?

Available 24x7 for emergency support.