This project demonstrates a three-tier architecture using Docker containers for a frontend, backend, and database setup. The setup involves:
- Database: MySQL
- Backend: Java (Spring Boot or Servlet-based)
- Frontend: HTML, CSS, JavaScript
Ensure you have the following installed:
- Docker
- Git
sudo yum install git -y
git clone https://github.com/abhipraydhoble/ThreeTier-Using-Docker.git
cd ThreeTier-Using-DockerNavigate to the database directory:
cd database- The Dockerfile:
- Uses the MariaDB base image.
- Sets the root password (1234).
- Copies student-rds.sql into the container for automatic database initialization.
- Starts the MariaDB service (mariadbd).
docker build -t my-mysql-db .docker run -d --name my-mysql-container -p 3306:3306 my-mysql-dbdocker inspect my-mysql-containerCopy this IP address for the next step.
Navigate to the backend directory:
cd ../backendEdit context.xml and replace <MYSQL_CONTAINER_IP> with the actual MySQL container IP from Step 2.3:
<Context>
<Resource name="jdbc/StudentDB" auth="Container"
type="javax.sql.DataSource" driverClassName="com.mysql.cj.jdbc.Driver"
url="jdbc:mysql://<MYSQL_CONTAINER_IP>:3306/studentdb"
username="root" password="root" maxTotal="10" maxIdle="5"/>
</Context>docker build -t my-backend-app .docker run -d --name my-backend-container -p 8080:8080 my-backend-appCheck if the backend is working:
curl http://<INSTANCE_PUBLIC_IP>:8080/studentReplace <INSTANCE_PUBLIC_IP> with your server's public IP.
Navigate to the frontend directory:
cd ../frontendEdit index.html and replace the backend URL:
<a href="http://54.169.189.50:8080/student/">Register Here</a>Replace <INSTANCE_PUBLIC_IP> with your actual server's public IP.
docker build -t my-frontend-app .docker run -d --name my-frontend-container -p 80:80 my-frontend-appNow, open your browser and go to:
http://<INSTANCE_PUBLIC_IP>
You should see the final application running!
- Check running containers:
docker ps - View logs:
docker logs my-backend-container - Stop all containers:
docker stop my-mysql-container my-backend-container my-frontend-container - Remove all containers:
docker rm my-mysql-container my-backend-container my-frontend-container