Skip to content

PrabalPiya/docker-compose-mutli-container-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Compose Multi-Container Application

This is a beginner DevOps project where I used Docker Compose to run a simple Node.js application and a MySQL database together.

The goal of this project is to understand how multiple containers work together in a local development environment.

What This Project Demonstrates

  • Running multiple containers with Docker Compose
  • Connecting an application container to a database container
  • Using environment variables for configuration
  • Using Docker volumes for database persistence
  • Adding a health check for MySQL
  • Checking container logs for troubleshooting

Tools Used

  • Docker
  • Docker Compose
  • Node.js
  • Express.js
  • MySQL
  • mysql2
  • VS Code
  • Git/GitHub

Folder Structure

devops-compose-basic-app/
│
├── app/
│   ├── Dockerfile
│   ├── package.json
│   └── server.js
│
├── db/
│   └── init.sql
│
├── docker-compose.yml
├── .env.example
├── .gitignore
└── README.md

How to Run

1. Clone the Repository

git clone <your-repository-url>
cd devops-compose-basic-app

2. Create .env File

Create a .env file in the root folder:

MYSQL_ROOT_PASSWORD=rootpassword
MYSQL_DATABASE=bookdb

DB_HOST=mysql
DB_USER=root
DB_PASSWORD=rootpassword
DB_NAME=bookdb
DB_PORT=3306

APP_PORT=3000

3. Start the Project

docker compose up --build

Or run in the background:

docker compose up -d --build

4. Verify Containers

docker compose ps

5. Test the Application

curl http://localhost:3000

Health check:

curl http://localhost:3000/health

Books API:

curl http://localhost:3000/books

6. Check Logs

docker compose logs app
docker compose logs mysql

7. Stop the Project

docker compose down

To remove the database volume and reset data:

docker compose down -v

About

Simple Docker Compose project running a Node.js Express app with a MySQL database in separate containers.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors