Skip to content

shaydevops2024/multi_stage_docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Go Calculator + Multi-Stage Docker Project

This project demonstrates a multi-container Docker setup with a Go backend and a static frontend, allowing users to:

  1. Perform simple calculations (add two numbers)

  2. Display all results dynamically on a browser

  3. The project is fully containerized with separate backend and frontend services.

πŸ“‚ Project Structure

project/
β”‚
β”œβ”€β”€ BE/                     # Backend service
β”‚   β”œβ”€β”€ Dockerfile          # Backend Dockerfile
β”‚   └── main.go             # Go backend code
β”‚
β”œβ”€β”€ UI/                     # Frontend service
β”‚   β”œβ”€β”€ Dockerfile          # Frontend Dockerfile
β”‚   β”œβ”€β”€ index.html          # Main HTML page
β”‚   └── static/
β”‚       └── styles.css      # Static files
β”œβ”€β”€ docker-compose.yaml     # Docker Compose configuration
└── README.md

Features:

Frontend

  • Accessible in the browser (port 9000)

  • Allows the user to:

    • Enter two numbers and click Calculate or press Enter

    • Display calculation results dynamically in a table

    • Press Restart to refresh the page

  • Styled with soft grey and orange tones and white backgrounds for inputs and table

Backend

  • Written in Go

  • Exposes APIs:

    • /add β†’ store a calculation dinamically
  • Multi-stage Docker build keeps image small and efficient


Docker Architecture:

  • Backend container

    • Runs Go backend

    • Listens on port 8000

  • Frontend container

    • Serves static HTML/CSS/JS

    • Listens on port 9000

    • Communicates with backend via API


Running the Project:

  1. Clone the repository
git clone <your-repository-url>
cd project
  1. Build and run containers
docker compose up --build
  1. Using the App
  • Open browser β†’ http://localhost:9000

  • Enter two numbers and click Calculate or press Enter

  • View the result in the table

  • Press Restart to refresh the page


Summary

This project uses Docker Compose to run two separate containers:

  • Backend container – runs the Go server handling calculation requests.

  • Frontend container – serves the static HTML, CSS, and JS interface in the browser.

The containers are isolated, yet communicate via exposed ports. The backend listens on port 8000, and the frontend serves the app on port 9000. Using Docker Compose makes it easy to build, run, and manage the application consistently across environments.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published