Skip to content

WhiteMuush/simplon-container-tp

Repository files navigation

Simplon Docker compose & Azure

Go Gin MongoDB Docker Compose HAProxy

A small Go (Gin) web API backed by MongoDB, orchestrated with Docker Compose and scaled behind an haproxy load balancer.

The two parts of this TP

The full briefs and explanations live in docs/:

This README only lists what to run to make each part work.

Prerequisites

  • Docker (with Compose v2)

Setup

cp .env.example .env
Variable Meaning Default
MONGODB_HOST MongoDB hostname db
MONGODB_PORT MongoDB port 27017

PART 1 Run docker compose

Start the stack (app + MongoDB):

docker compose up --build

Test:

curl http://localhost:5000/ping     # {"message":"pong"}

Live rebuild on file change

docker compose watch

Edit main.go line 57 (the pong message), save, then curl again to see the new response. Compose rebuilds the app automatically.


PART 2 Run scaled behind the load balancer

Requires haproxy.cfg (at the repo root) and the lb service in compose.yml.

Start with 3 app replicas + haproxy:

docker compose up -d --scale app=3

Test through the load balancer:

curl http://localhost:5000/ping     # {"message":"pong"}

Check the traffic is spread across the 3 replicas:

for i in $(seq 1 12); do curl -s http://localhost:5000/ping > /dev/null; done
for c in 1 2 3; do
  echo "app-$c: $(docker logs simplon-compose-tp-app-$c 2>&1 | grep -c '"/ping"')"
done

Counts should be roughly equal (e.g. 7 / 7 / 7).

Troubleshooting

  • Connection reset by peer: the lb container is down. Check docker compose logs lb.
  • Missing LF on last line: haproxy.cfg must end with a newline, or haproxy refuses to start.

Stop

docker compose down

About

TP Simplon ~ ( Mirror of GitLab ) A small Go (Gin) REST API backed by MongoDB, orchestrated with Docker Compose. The app is scaled across multiple replicas behind an HAProxy load balancer.

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages