Flux7 Flux7
  • Digital Innovation
      • Digital Innovation
      Enable Software Innovation
      • CI/CD: Accelerate Deployments Through Pipelines
      • Containers Infrastructure:Improve Agility with Containers
      • Build:Custom Toolchain Deployment
      • Microservices: Speed Application Development
      • HPC:Product Design & Simulation
      • Renovate:Application Migration to the Cloud
      • Serverless:Innovate at the Speed of the Market
      Scale Enterprise DevOps
      • AWS DevOps Consulting:  Refactor Large Quantities of Apps to AWS
      • Cloud-Native Architectures: Accelerate Business with Cloud-Native Services
  • Operational Excellence
      • Services
      Cloud Implementation Services
      • Cloud Migration Services: Streamline Your Cloud Migration
      • Build Cloud Foundations: Accelerate Adoption with Strong Cloud Foundations
      • ISV Workloads on Cloud: Defined Solutions and Proven IP
      • High-Performance Computing Services: Exploit Cloud Elasticity and Scalability
      Enforce Security and Compliance
      • Automate Compliance: Meet Corporate and Legal Requirements
      • Web Application Firewall:Protect Vital Data and Functions

      Our landing zones on AWS emphasizes training, documentation, and resources to help teams new to AWS get the skills they need for long-term business agility.

      Gain a Landing Zone That Fits Your Needs Today

  • Industries
      • Industries
       
      • Energy:Cloud Solutions for the Energy Industry
      • Finance: Secure Infrastructure for Improved Customer Service and Analytics
      • Healthcare & Life Sciences: Meet Security & Compliance Requirements
      • Hospitality: Increase Customer Acquisition
       
      • Manufacturing: Innovation with Digital Transformation
      • Retail:Grow Customer Loyalty and Lifetime Value
      • Semiconductor: Legacy Modernization Services
      • Software:Grow Developer Agility and Application Reliability
       

      Read our industry success stories and the benefits our customers saw

      Read the Case Studies

  • Tech
      • Tech
      Flux7 Tech
      • DevOps Toolchain: Reduce DevOps Challenges
      • Amazon Web Services: Reduce Complexities and Risks in AWS Architectures
      • AWS Database Services: Design and Implementation of Infrastructure for Cloud-Based Databases
      Configuration
      • Cloud Configuration: Gain Greater Consistency, Repeatability & Agility
      • HashiCorp Terraform: Defining Infrastructure as Code 
      • AWS CloudFormation: Reduce Maintenance and Improve Security
      Containers
      • Container Infrastructure: Improve Agility with Containers
      • Docker: Build, Ship and Run Applications Anywhere
      • Kubernetes: Container Consulting Services
      • Red Hat OpenShift: Speed Code Delivery

      Rapidly adopt technology to achieve Infrastructure as Code and continuous delivery and support of applications and workloads.

      Create Your DevOps Toolchain

  • Resources
      • Resources
      Research & Reports
      • Analyst Insights & Reports
      • Blog
      • Case Studies
      • White Papers
      News & Events
      • Events Calendar
      • Newsroom
      • Press Releases
      Flux7 Academy
      • Tech Tutorials

      Read about what we do, how we do it and how our customer's benefit from our solutions.

      Read and Download Our Case Studies

  • About
      • About Flux7
      Get To Know Us
      • About Flux7
      • Awards & Recognitions
      • Meet Our Team
      Work With Us
      • Careers
      • Our Culture
      Partner With Us
      • Flux7 partners with technology vendors who deliver solutions to help our customers address scalability, security, reduce the cost of infrastructure delivery and improve speed to market.

      Welcome to Flux7! Get to know us a bit better and discover what makes us different than other DevOps Consultants.

      Discover What Makes Us Different

  • Contact us
An NTT DATA Company

Login Contact us

10 Steps Deploying Docker Containers on AWS Elastic Beanstalk

10 Steps Deploying Docker Containers on AWS Elastic Beanstalk

By Flux7 Labs
November 19, 2019

Amazon Web Services (AWS) Elastic Beanstalk (EB) is a service to deploy your code. This easy-to-use service works as a Platform as a Service (PaaS). It supports familiar web applications, such as PHP, Node.js, Ruby, Python, Java and .Net. You can simply choose your software stack and upload your code. AWS will take care of the provisioning of the environment, deploying the code, load balancing, auto scaling, and health monitoring. At the end of the process, it prints a url used to access the application.

Recently, AWS added support for Docker containers. Before Docker, EB limited your choices to available stacks in the drop-down list. This forced you to choose predefined versions offered by AWS. For example, by default, PHP on EB runs on Apache. If you want to replace Apache with Nginx+PHP-FPM, there is no way you can do that. Customization of Amazon Machine Images (AMI) used in EB is very limited.

But now Docker is enabling flexibility for users to deploy any software stack in EB.

You are no longer solely dependent on software versions supported by EB. You can run whatever you want or need to in a container, and deploy it to EB. You can run multiple Tomcat or MySQL servers, or even multiple Apache servers, in a single container. You can even run your own customized Java service in a container and deploy it to EB.

Sound interesting? Ready to evaluate Docker? Then let’s discuss how you can deploy a Docker container in EB using 10 easy steps.

There are three ways you can deploy docker containers in EB. We assume you already know about the Docker concepts. If you don’t know about Docker, you can get a quick study here.

Here are the three ways:

1. Create a Dockerfile and upload it to EB.

2. Create a Dockerrun.aws.json file to deploy an existing Docker image.

3. Create a zip file with Dockerfile, Dockerrun.aws.json, and any application file, then upload to EB.

Dockerrun.aws.json: This is specific to AWS EB. This describes how to deploy a container in EB. (Learn more here.)

In the following 10-step tutorial, we are describing how to deploy a pre-baked Docker container from a Docker repo to AWS EB.

1. Create S3 bucket.

2. Commit Docker image.

Create a Docker image using all the required packages installed, the deploy the code. If the database is outside of the container, then be sure you have deployed the updated code.

Commit the Docker image to Docker repo.

3. Create Docker Authentication configuration file:

  • Login to Docker repo using Linux terminal.
$ docker login
  • It prompts you for the logins and email. Once you enter the credentials, Docker creates .dockerconfig file in the user’s home directory.

 

  • Upload the dockerconfig file to the S3 bucket. EB will read this file to get the access to Docker repo.

 

The config file will then look like this:

{"https://index.docker.io/v1/":{"auth":"XXXXXXXXXXXXXYYYYY”==","email":"sysadmin@flux7.com"}}

4. Create Dockerrun.aws.json

This file describes how to deploy a container in AWS EB. Please see the configuration file here:

In the Authentication section, we have provided the bucket name and key value. Key is the location for the dockercfg file. Here, we have created a folder called “docker” in the flux7.com bucket and uploaded the configuration file into it. You may notice that we have renamed .dockercfg to dockercfg. You can rename it to whatever your desire. Using dockercfg EB pulls the container from the Docker private repo. The Ports section describes which ports are to be exposed from the Docker container. AWS Elastic Beanstalk uses the ContainerPort value to connect the Docker container to the reverse proxy running on the host. We run Apache inside our container, so we need 80 port to be exposed. The EB instance runs Nginx as a proxy. You can add configurations for logging and file system sharing, too. You can see more of this at here

5. Create Dockerfile

When you begin a Docker container, it doesn’t run any default services. So, we need to pass on a command to start the services. By using supervisor, you can start multiple services automatically while the container starts. (Learn more here.) We now have saved a container with Apache, MySQL and PHP installed and our application deployed. It’s now time to push the container to Docker repo. Below is the Dockerfile we have created. This installs supervisord at the container startup and uploads the supervisord.conf:

6. Create supervisord.conf

Below is the example supervisord.conf file we have created. This file is responsible for starting the required services in container.


It’s designed to allow SSH, MySQL and Apache services to begin at the container start up. You can add as many services here as you need to start at the container boot-up.

7. Create AWS IAM Role

Create an IAM role and attach the user policy with S3 bucket access.

8. Compress the files into a ZIP

Now ZIP all files into a single file.

zip flux7-env.zip Dockerfile Dockerrun.aws.json supervisord.conf

Note: Do not copy them into a directory and zip the directory. EB doesn’t read the directory zip.

9. Create ELB environment

i. Login to AWS Console and navigate to the Elastic Beanstalk page.

ii. At the right side top, click “Create New Application.” Application Name: Give any name for your application. Example: flux7-dev. Description: Add some description. Then click Next.

  1. Environment Type – Environment Tier:Select “Web Server 1.0” (Learn more here.) Predefined configuration: Select “Docker” from the drop-down menu. Environment type: Choose “single instance” or “auto scaling.” For demo purpose, we chose single instance.
  2. Application Version – Select “Upload Your Own” and upload the zip file created in the above step. Then click “next.”
  3. Environment Information – Environment name: Give your desired name to the environment. Example: flux7-dev. Environment URL: Provide the URL for your application. This is only for internal purposes. Description: Add some description.
  4. Additional Resources – You can select to create an RDS instance with EB. If you choose the RDS, then you will have to update the application code to point to the RDS instance. Select “Create the environment inside a VPC.” Then click “next.”

vii. Configuration Details – Instance type:Choose desired instance type. At least choose m1.small to make the app work without any hiccups. EC2 key pair:Select the “KeyPair” for the instances launched by EB. Email address: Enter your email address to receive the notifications from CloudWatch. Instance Profile: This is important. You need to choose the IAM role created above.

viii. Environment Tags: You can add any tags you want or leave them blank.

ix. VPC Configuration – VPC: Select a VPC from the drop-down list to create the instance. Select Subnets:Choose the subnets from the table shown. You may only select one EC2 subnet per AZ. VPC Security Group:This is the security group for the instances created by EB.

x. Review the configurations and click “Launch”: In a few minutes, you will have the servers provisioned and the Docker container deployed. If everything goes as expected, environment turns from the grey color to the green color. Now, you can access the application with the EB url. In case the environment fails to provision or turns to the red color, you can check the Events section for the details.

10. Update Docker Containers

If you want to deploy new code to the EB, then you need to create a new Docker image and push it to Docker repo.

If the Docker image name is the same, then, by selecting rebuilding, the environment will deploy the latest Docker container.

If you have a container with a different name, then you need to update the dockerfile and create a zip file again. Once you have done this, upload and deploy it to EB.

There you have it. A quick, but complete, Docker case study about deploying Docker containers on AWS Elastic Beanstalk. 

Looking for more information on Docker? Many organizations are extending Docker containers to support a microservices strategy. For more information in microservices on AWS, see this link. 

Get Started with AWS

Receive AWS tips, DevOps best practices, news analysis, commentary and more. Sign up for our IT Modernization blog here and set your topic and frequency preferences. Or, download our guide on getting started with AWS, establishing a secure AWS enterprise architecture with Flux7 Landing Zones.

Share This Article
Facebook Twitter Pinterest Linkedin
Prev Post
Next Post

Related Articles

IT Modernization and DevOps News Week in Review 1.18.2021
By Flux7 Labs
January 18, 2021

IT Modernization and DevOps News Week in Review 1.18.2021

READ MORE
re:Invent Round-Up of AWS DevOps Announcements
By Flux7 Labs
December 21, 2020

re:Invent Round-Up of AWS DevOps Announcements

READ MORE

Recent Posts

  • IT Modernization and DevOps News Week in Review 1.18.2021

  • re:Invent Round-Up of AWS DevOps Announcements

  • How Will SASE Change Networking in 2021?

  • AWS re:Invent Machine Learning Round-Up

  • How to Publish Managed Images to the Azure Marketplace

  • AWS re:Invent News Round-Up

  • Shave Days off Azure Marketplace Publishing with Automated Testing

  • IT Modernization and DevOps News Week in Review 11.30.2020

  • How To: Multi-Cluster Monitoring in Amazon EKS

  • IT Modernization and DevOps News Week in Review 11.16.2020

Flux7
  • About Flux7
  • Contact Us
  • Careers at Flux7
  • Newsroom
  • Meet our Team
Services
  • Enable Software Innovation
  • Enforce Security and Compliance
  • Adopt Cloud
  • Cloud Migration Services
  • Secure the Cloud
Resources
  • Analysts Reports
  • Case Studies
  • White Papers
About Flux7

Flux7, an NTT DATA Company, helps enterprises reduce the complexities of new and evolving cloud automation strategies. Agile and DevOps-native, Flux7’s robust IT services portfolio prioritizes a fast path to ROI, is transformation focused and creates secure and stable pathways for operational excellence.

Follow Us
Flux7, an NTT DATA Company | All Rights Reserved | Privacy Policy