3tier Studentapp Hosting With Dockerfile
3tier Studentapp Hosting With 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
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
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
cd ..
cd frontend/
ls
docker build -t frontendstudentapp .
docker run -d -p 81:80 256