Start a Project

How To Deploy A Docker Container To AWS Elastic Beanstalk

Docker Container

A Docker container is a standard unit of software that packages up all code and its dependencies so the application runs faster and reliably from one computing environment to another computing environment.

AWS Elastic Beanstalk

AWS Elastic Beanstalk is a service used for deploying and scaling web applications and services. Upload your code and AWS Elastic Beanstalk will manage deployments automatically.

Prerequisites

Step 1: Creating a Docker Web-Host

Create an html index file to add to the docker host.

<center> <h1><font color="ORANGE">Hii! This Is My Demo.</font></h1> </center>

Save the code as a file of “index.html”.

Create a docker file for build and running the web-host container.

FROM nginx

ADD index.html /usr/share/nginx/html

EXPOSE 80

Save the file as “Dockerfile“.

Build dockerfile

$ docker build -t web .

A docker image will build by using the above command. We are running a docker container by using the build image.

$ docker run –name web-host -p 8080:80 web

Browse the URL by using the server’s public IP http://PublicIP:8080.

You will get this page by browsing http://PublicIP:8080.

Step 2: Deploying Website To Elastic Beanstalk via AWS CLI

Your container is accessible on your machine, So now it is time to deploy your website to AWS Elastic Beanstalk.

Use elastic beanstalk cli for deploying the docker container “web-host” to AWS Elastic Beanstalk.

First, You have to install and configure AWS cli then proceed to eb cli initialization.

$ eb init

After initialization, you get a prompt for some details requested by the server.

There are some examples:

Default Region: 6

Application Name: web-host

It appears you are using Docker. Is this correct? Y

Select a Platform Branch: 1

Do you wish to continue with CodeCommit? N

Do you want to set up SSH for your instances? N

$ eb create

Use the default value or use your desired name/value.

Enter the value for the environment, DNS cname, load balancer, and application name, or use the default value.

It takes time to create an environment, Cluster, Security Group, Load Balancer, and S3 file store.

Open the below URL on your browser.

URL – http://web-host.ap-south-1.elasticbeanstalk.com

Note: Use your created elastic beanstalk host in place of a web host.

If you want to change in code and re-deploy the elastic beanstalk host.

Here we going to change the color of heading-1(h1) in the index.html file.

<center> <h1><font color="GREEN">Hii! This Is My Demo.</font></h1> </center>

Change/Edit code and save as “index.html“.

$ eb deploy web-host

Note: Replace your created host in place of web-host to deploy

Hit the URL: – http://web-host.ap-south-1.elasticbeanstalk.com again and you get the changed image as shown below.

Note: Every “eb” command will work under your created environment directory(have Dockerfile and index.html files included in the directory).

Need Support?

Thank You for reading this Blog!

For further more interesting blogs, keep in touch with us. If you need any kind of support, simply raise a ticket at https://webkul.uvdesk.com/en/.

You may also visit our CS-Cart development services and quality CS-Cart Extensions.

For further help or query, please contact us or raise a ticket.

Exit mobile version