Post2

Packaging Web Applications into Dockers, for AWS Containerized Deployments

Posted by Neeraj Virmani

Overview and Benefits

Packing applications into Docker containers allows developer to quickly deploy an application with all its dependencies, which are bundled into a single container and deployed anywhere without compatibility issues.

Key benefits of packaging web application in Docker image:

  • Simple and faster configurations
  • Environment independent deployment
  • Rapid application deployment
  • Easy and fast deployment
  • Symmetric deployment to multiple host

 

Steps to Package web application into Docker Container – 

  • Download a Docker file for a tomcat installation from the below URL.

https://github.com/docker-library/tomcat/blob/9040855496452d91d7b0d8abbfd70c60448a07a1/8.5/jre8-alpine/Dockerfile

  • Build an image using the Docker file:

docker build -t <tomcat>

  • Run the container and map host port 9002 to container’s port 8080:

docker run -d -p 9002:8080 <image_id>

  • Deploy the sample war file to the tomcat

Copy the sample war file to the container’s tomcat webapps folder:

docker cp <sample_war> <container_id>:/usr/local/tomcat/webapps

  • Get inside the running container

docker exec -it <container_id> bash

  • Change directory to bin and Stop tomcat:

 cd bin;   ./catalina.sh stop

  • Start tomcat:

./catalina.sh start

  • Exit the container

exit

The container is modified and it has the sample war file which is running at port 9002.

  • Commit the changes made to the container:

docker commit -a <author_name> <container_id> <repo_name>:<tag_name>

  • Stop and remove all running containers

docker stop $(docker ps -a -q)

Next… –

  • Create container using image created above which have tomcat installation with CAE war file deployed to webapps folder:

docker run -d -p 9002:8080 <image_id>

  • Tomcat would be up and running with sample application deployed on it.

<ip_address>:9002/<sample_app>

 

Container Deployment on AWS

Push Docker Image on repository

The first thing that we need to do before we deploy our app to AWS is to publish our image on a registry which can be accessed by AWS. There are many different Docker registries you can use (you can even host your own). For now, let’s use Docker Hub to publish the image.

If this is the first time you are pushing an image, the client will ask you to login. Provide the same credentials that you used for logging into Docker Hub.

$ docker login

$ Username: your_username

$ Password: your_password

Login Successful

To push your image to Dockerhub repository,

$ docker push docker_username/app_name

AWS Elastic Beanstalk (EB) is a PaaS (Platform as a Service) offered by AWS. To use AWS Elastic Beanstalk we need a functioning AWS account.

  • Give your app a memorable (but unique) name and provide an (optional) description

  • Click on “Next”
  • In the New Environment screen, choose the Web Server Environment

  • Click on “Create web server”
  • In the Environment Type screen, choose Docker from the predefined configuration. Choose Environment type as “Load balancing, auto scaling” and Click on “Next”

  • Create a Dockerrun.aws.json file and put the information about your Docker image

  • In the Application version page, select the source and upload the Dockerrun.aws.json file

  • Leave rest of the options as it is and click “Next”
  • In the Environment Information page, give an environment name and environment URL, Click “Next”

  • In the additional resources page, click “Next”
  • In the configuration details, select instance type as “t2.micro” and leave rest of the options as default and click “Next”

  • On the Environment Tags and Permissions page, click “Next”. At the end, you’ll see a “Review Page”. If everything looks good, go ahead and press the “Launch Button”.
  • The final screen will show you a few spinners indicating that your environment is being set up. It typically takes around 5 minutes for the first-time setup.
  • Go ahead and open the URL in your browser and you should see the application running.

 

Related Posts

  • Continuous Deployment using Dockerized ApplicationContinuous Deployment using Dockerized Application

    Dockerized Applications Dockerized applications are applications that are packed into a Docker image and stored on a Docker repository. These Docker images are used to provision applications along with the…

  • Mobile App Development and Continuous Delivery – Introduction to Docker (1/7)Mobile App Development and Continuous Delivery – Introduction to Docker (1/7)

    DevOps has changed the way application development is done and has significantly influenced mobile app development too! DevOps methodology help bridge the gap between development and operations within an organization,…

  • Teradata Intelligent Memory (TIM)

    Overview of Teradata Teradata is a RDBMS (Relational Database Management System). This system is solely based on off-the-shelf (readymade) symmetric multiprocessing (SMP) technology combined with communication networking, connecting SMP systems…

  • Perl One-LinersPerl One-Liners

    What are Perl One-Liners? As the name suggests, Perl One-Liners are small single line of codes that can perform several tasks, ranging from changing line spacing and numbering lines to…

  • Microservices ArchitectureMicroservices Architecture

    Coined over a decade ago, Microservices is a buzzword in today’s technical arena. Microservices are known as micro web services based on SOAP and enables breaking of a large system…

  • Introduction to Microservices

    Traditional development methodologies encourage the ‘monolithic’ approach to application development. Building a single application that does everything required has been the modus operandi for a while. However, with the rise…

Leave a Reply

Your email address will not be published. Required fields are marked *