0% found this document useful (0 votes)
16 views4 pages

3tier Studentapp Hosting With Dockerfile

The document outlines the steps to host a 3-tier application called 'studentapp' using Ubuntu AMI, including the creation of an RDS instance with MariaDB and the deployment of backend and frontend components using Docker. It details the configuration of Dockerfiles for both backend and frontend, along with the necessary files and commands to set up the application and database. Additionally, it includes instructions for modifying security groups and testing the application via specified ports.

Uploaded by

banda.aws09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

3tier Studentapp Hosting With Dockerfile

The document outlines the steps to host a 3-tier application called 'studentapp' using Ubuntu AMI, including the creation of an RDS instance with MariaDB and the deployment of backend and frontend components using Docker. It details the configuration of Dockerfiles for both backend and frontend, along with the necessary files and commands to set up the application and database. Additionally, it includes instructions for modifying security groups and testing the application via specified ports.

Uploaded by

banda.aws09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

We are going to host 3 tier application with frontend backend and database.

The application we are


going to host is studentapp

We have chosen Ubuntu ami for this project

1) Create a RDS with only following changes


standard create
database engine:mariadb
template:free tier
settings:instance name: any name, username:admin, password:Redhat123
instance configuration:default
storage:default
availability and durability:
connectivity: don’t connect to ec2 instance
vpc:default, SG:default
2) We will deploy backend. We created an instance. We created a folder backend in repository for
Dockerfile and also we put mysql-connector.jar, student.war and context.xml in same repo.
Note: in context.xml has our rds username credentials, password credentials and rds endpoint.
(we have to edit those)
Contents of Dockerfile 

FROM ubuntu:latest
LABEL Backend="studentappbackend"
ADD https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.93/bin/apache-tomcat-9.0.93.zip /opt
WORKDIR /opt/
RUN apt update && \
apt install unzip openjdk-11-jdk -y && \
unzip apache-tomcat-9.0.93.zip && \
chmod +rwx /opt/apache-tomcat-9.0.93/bin/*.sh
COPY mysql-connector.jar /opt/apache-tomcat-9.0.93/lib/
COPY student.war /opt/apache-tomcat-9.0.93/webapps/
COPY context.xml /opt/apache-tomcat-9.0.93/conf/
EXPOSE 8080
CMD ["/opt/apache-tomcat-9.0.93/bin/catalina.sh" , "run"]

Contents of context.xml 

<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software


distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context>
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource" maxTotal="100"
maxIdle="30" maxWaitMillis="10000" username="admin" password="Redhat123"
driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://database-2.cxcsyc6awrpf.ap-
south-1.rds.amazonaws.com:3306/studentapp"/>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
</Context>

Install and configure docker from Install Docker Engine on Ubuntu | Docker Docs on the instance

sudo –i
git clone https://github.com/learnerkaran/docker-file-prac.git
apt-get install mysql-server –y
mysql -h database-2.cxcsyc6awrpf.ap-south-1.rds.amazonaws.com -u admin -pRedhat123
create database studentapp;
use studentapp;
CREATE TABLE if not exists students(student_id INT NOT NULL AUTO_INCREMENT,
student_name VARCHAR(100) NOT NULL,
student_addr VARCHAR(100) NOT NULL,
student_age VARCHAR(3) NOT NULL,
student_qual VARCHAR(20) NOT NULL,
student_percent VARCHAR(10) NOT NULL,
student_year_passed VARCHAR(10) NOT NULL,
PRIMARY KEY (student_id)
);
Exit
cd docker-file-prac/ 3tier/backend/
ls

docker build -t backendstudentapp .


docker run -d -p 8080:8080 a67

hit the instanceip:8080/studentapp to ckeck if it is working

Note: Edit security group: inbound rule: “Custom TCP” “port 8080” “all ip’s” and
“mysql/aurora(for mysql)” “port 3306” “all ip’s”

3) Now we will deploy frontend. We will have created Dockerfile and index.html in the same repo
but in folder name frontend.
Note: href in index.html should point to http://instanceip:8080/student to point to our backend.

Contents of Dockerfile 

FROM ubuntu:latest
LABEL Frontend="studentappfrontend"
RUN apt-get update && \
apt-get install apache2 -y
COPY index.html /var/www/html/index.html
EXPOSE 80
CMD ["apachectl", "-D" ,"FOREGROUND"]

Contents of index.html

<h1 style="text-align: center;"><span style="color: #ff0000;">Welcome to Student Application


on AWS.</span></h1>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://cdn-images-
1.medium.com/max/2000/1*tFl-8wQUENETYLjX5mYWuA.png" alt="" width="1200"
height="630" /></p>
<p>&nbsp;</p>
<h2 style="text-align: center;"><a href="http://43.205.199.20:8080/student/"><strong>Enter to
Student Application</strong></a></h2>
<p>&nbsp;</p>
<p>&nbsp;</p>

cd ..
cd frontend/
ls
docker build -t frontendstudentapp .
docker run -d -p 81:80 256

now hit the instanceip: 81 and check the result.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy