Skip to content

Repository files navigation

Multi-Container Blog (Node.js + MySQL)

Docker Node.js MySQL

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.

Project Features

  • 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.

Project Structure

  • 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.

Getting Started

Prerequisites

  • Docker
  • Docker Compose

Installation

  1. Navigate to the project directory:

    cd Docker-Projects/Multi-Container-Blog
  2. Build the application:

    docker compose build

Usage

  1. Start the containers:

    docker compose up
  2. Verify the containers are running:

    docker ps
  3. View all blog posts:

    curl http://localhost:3000/posts
  4. Create a new blog post:

    curl -X POST http://localhost:3000/posts \
    -H "Content-Type: application/json" \
    -d '{"title":"Docker","content":"My first blog"}'

Verification

  1. View running containers:

    docker ps
  2. View application logs:

    docker compose logs
  3. Retrieve all posts:

    curl http://localhost:3000/posts
  4. Verify Docker volumes:

    docker volume ls

Cleanup

Stop the containers:

docker compose down

Stop the containers and remove the volume:

docker compose down -v

About

A multi-container blog application using Docker Compose with Node.js and MySQL to demonstrate service orchestration, container networking, and persistent data storage.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages