A simple multi-container blog application built with Node.js, Express, MySQL, and Docker Compose. This project demonstrates how multiple containers communicate over a Docker network while using Docker volumes for persistent database storage.
- REST API: Create and retrieve blog posts.
- Multi-Container Architecture: Separate containers for the application and database.
- Docker Compose: Manages multiple containers with a single command.
- Persistent Storage: Stores MySQL data using Docker volumes.
- Automatic Database Setup: Creates the database table on startup.
- Database Retry Logic: Automatically reconnects if MySQL is still initializing.
- app.js: Main Express application.
- package.json: Project metadata and npm configuration.
- package-lock.json: Dependency lock file.
- Dockerfile: Builds the Node.js application image.
- docker-compose.yml: Defines the application and MySQL services.
- .dockerignore: Excludes unnecessary files from the Docker build context.
- .gitignore: Prevents unnecessary local file from being tracked by Git.
- Project-7.png: Project banner for GitHub and LinkedIn.
- README.md: Project documentation.
- Docker
- Docker Compose
-
Navigate to the project directory:
cd Docker-Projects/Multi-Container-Blog -
Build the application:
docker compose build
-
Start the containers:
docker compose up
-
Verify the containers are running:
docker ps
-
View all blog posts:
curl http://localhost:3000/posts
-
Create a new blog post:
curl -X POST http://localhost:3000/posts \ -H "Content-Type: application/json" \ -d '{"title":"Docker","content":"My first blog"}'
-
View running containers:
docker ps
-
View application logs:
docker compose logs
-
Retrieve all posts:
curl http://localhost:3000/posts
-
Verify Docker volumes:
docker volume ls
Stop the containers:
docker compose downStop the containers and remove the volume:
docker compose down -v