Deploying Docker Container in AWS Elastic Beanstalk

Reading Time: 4 minutes

Hello Readers! In this we will see how to deploy a single docker container in AWS Elastic Beanstalk. Earlier we have seen how to deploy applications in Elastic Beanstalk. There we have seen how AWS takes care of all underlying resources so you don’t have to worry about anything. You can purely concentrate on writing your application code, package it and upload it. And EBS takes care of its infrastructure and resources.

Before starting you must have AWS configured and EB CLI installed on your system. For installing do prefer my blog: https://blog.knoldus.com/how-to-setup-eb-cli/

So, Let’s start!

Step 1: Install EB CLI and configure AWS.

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.

Paste this sample code there.

Now we will create a dockerfile of the application.

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

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.

Initialization is done now.

Step 3: On AWS Management console select Elastic Beanstalk.

When you open it you will not find any environment created here. So, Firstly let’s create it by using the following command.

Enter their environment name as per your wish.

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

Now you find here that process is starting….

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. 

After some time the environment got created.

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

You will find one EC2 instance created.

S3 Bucket is also created you can see here.

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

Step 4: Open your application by following command.

It will open a browser where you can see your application.

That’s all! You have successfully deployed a docker Container in AWS Elastic Beanstalk. 

Now, if you want to update your application. This is also so simple just update your source code and use the following command.

image

This command will create an application version. It will update the Elastic Beanstalk environment. It will just start the docker container and launch another docker container on the same instance. 

When you will run eb open you will see the updated version.

We are all done now!

Conclusion

So, In this blog we saw with a few easy steps how we can deploy a docker container in Elastic Beanstalk and you can also change the configuration as per your requirement. Thanks for being with me till the end. If you find this blog helpful do share with your friends.

HAPPY LEARNING!

knoldus

Written by 

Naincy Kumari is a DevOps Consultant at Knoldus Inc. She is always ready to learn new technologies and tools. She loves painting and dancing.