DEV Community

Piyush Chaudhari for AWS Community Builders

Posted on

Deploying Sample Docker Container to AWS Elastic Beanstalk (PAAS)

Elastic Beanstalk is an AWS service that leverages Amazon EC2 and S3 and deploys, manages and scales your web applications for you. It uses managed containers that support Node.js, Java, Ruby, Docker and more. There are multiple ways to deploy applications using Elastic Beanstalk. You can deploy using the management console, the CLI, or the API. The amazing thing about Elastic Beanstalk is that once you upload your application, it takes care of things like load balancing, health monitoring, scaling, and more. Check out more information on Elastic Beanstalk
Overall, Elastic Beanstalk builds your docker image using your uploaded source code, and then it is deployed to EC2 instances running in an Elastic Beanstalk environment.

In this demonstration, we will:

  • Create an IAM User with sufficient privileges to it to manage AWS Elastic Beanstalk environment and generate Access keys, Secret keys. These keys will help us to configure AWS CLI. Here, I have created IAM User named "eb-demo-piyush". IMAGE
  • Deploy our Docker container with Elastic Beanstalk using a single container configuration (run 1 container per EC2 instance), using the Elastic Beanstalk CLI via AWS Cloud Shell because it is prebuilt with EB CLI along with AWS CLI. Check out more information on AWS Cloud Shell
  • Use a Dockerfile for our configuration for simplicity.
  • I will be using eu-central-1 as my AWS region.

So, Let’s start!

Step 1: Lets check the EB CLI version and lets start configuring the AWS CLI via AWS Cloud shell to talk to respective AWS services via APIs

Image description

I attached AdministratorAccess-AWSElasticBeanstalk AWS managed policy to my IAM User "eb-demo-piyush".

Image description

Lets check AWS CLI version and configure it with generated access and secret keys of my IAM User "eb-demo-piyush".

Image description

Step 2: In order to deploy a docker container in AWS Elastic Beanstalk we need an application and dockerfile for that application. So, here we will create a simple application and its dockerfile.

Image description

Paste the below code and save the file.

<!DOCTYPE html>
<html>
<body>
<center>
<h1> <font color="GREEN"> Don't Stop Trying, Until You Succeed in Doing!!! </font> </h1>
</center>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Image description

Now we will create a dockerfile of the application.
Paste the below content in Dockerfile.

FROM nginx
ADD eb-app-piyush.html /usr/share/nginx/html/
EXPOSE 80
Enter fullscreen mode Exit fullscreen mode

Image description

Step 3: Initialize your Elastic Beanstalk Environment. By initializing Elastic Beanstalk knows about what type of application you are about to deploy here.

Image description

It will ask for an Application name.
It will give options for selecting a platform branch. Here default is option 1 so, let’s move to the default one.
Now it will ask if you want to set up a SSH for your instance. I say No to it.

Image description

Initialization is done now. On AWS Management console select Elastic Beanstalk. You will see the new Application created. But, when you open it, no environment exists.

Image description

Step 4: Lets create the environment for the application created.

Image description
Enter their environment name as per your wish.

Image description
Select the type of load balancer. I will go with the default one.

Image description
I will say No to Spot Fleet requests.

Image description
Now the application version will be uploaded to S3 and it will start the process of creating the Environment.

Image description
This process of createEnvironment will take at least 2-3 minutes. You will see here that resources are being created like target groups, security groups etc.

Image description
After some time the environment got created.

Image description
You can recheck it on Elastic Beanstalk. It is successfully created now.

Image description
You will find one EC2 instance created.

Image description
Lets check S3 Bucket which got created.

Image description
You can check the status of the application by using the following command.

Image description
Now, since the status of Elastic Beanstalk environment is healthy, if you want, we can browse the Application Load Balancer URL.


Bingo..!!! We have successfully deployed a Sample docker container based app to AWS Elastic Beanstalk (PAAS) !!!

Its time to wrap up..

OK, folks that’s it for this post. Have a nice day guys…… Stay tuned…..!!!!!

Don’t forget to like & share this post on social networks!!! I will keep on updating this blog. Please do follow me on "LinkedIn" & my other blogs -
cpiyush151 - Wordpress
cpiyush151 - Hashnode

Top comments (0)