Shivraj's Docker Compose Blog

Author Image

About the Author

Hi, I'm Shivraj Nakum, CSE student and a passionate developer with a love for exploring technologies.This is part of Cloud IA-2 project.
Roll no: 21BCP125

I created this blog to share my experiences and insights about Docker Compose and its practical applications.

Docker Compose Experiment Steps

Step 1: Create dockerfiles in application

create dokcer files in fronten , backend and database folders

Step 1: Create dockerfiles in application

Step 2: Write dockerfile for frontend

This file specifies the base image, install any necessary dependencies, and define the command to start the frontend server.

Step 2: Write dockerfile for frontend

Step 3: Write dockerfile for backend

This file specifies the base image, install any necessary dependencies, and define the command to start the backend server.

Step 3: Write dockerfile for backend

Step 4: Write dockerfile for database

This file specifies the base image for the database, and any necessary setup commands to initialize the database.

Step 4: Write dockerfile for database

Step 5: Write init.sql script for database

This script includes commands to create tables, insert initial data into application's database.

Step 5: Write init.sql script for database

Step 6: Write docker-compose file for the application

docker-compose.yml
Step 6: Write docker-compose file for the application

Step 7: Now we will build the application and run

docker-compose up --build
Step 7: Now we will build the application and run

Step 8: Now we can see the container are created and running

Step 8: Now we can see the container are created and running

Step 9: We can also check running container through command

docker ps
Step 9: We can also check running container through command

Step 10: Now you could view frontend on http://localhost/

Step 10: Now you could view frontend on http://localhost/

Step 11: Now you could view backend at http://localhost:3000/

Step 11: Now you could view backend at http://localhost:3000/

Step 12: Now we will view the database

docker exec -it container_id_of_database mysql -u username -p
Step 12: Now we will view the database

Step 13: Check if Database is created or not

show databases;
Step 13: Check if Database is created or not

Step 14: Now use the databse

use databses;
Step 14: Now use the databse

Step 15: See the entry in database

select * from ia_2_table;
Step 15: See the entry in database

Step 16: Now check the images

docker images
Step 16: Now check the images

Step 17: Now tag the image to your dockerhub account

docker tag cloud_ia-2_three_tier_app-frontend shivraj03/cloud_ia-2_three_tier_app-frontend
Step 17: Now tag the image to your dockerhub account

Step 18: Now push the image on Docker hub account

docker push shivraj03/cloud_ia-2_three_tier_app-frontend
Step 18: Now push the image on Docker hub account

Step 19: Now check the images in dockerhub account

Step 19: Now check the images in dockerhub account

Here are links to the Docker Hub images

Frontend Database Backend

Github link of three-tier-app

This contains the whole application and explanation of dockerfiles.

GitHub Logo