🔗
Docker Compose

URL Shortener Microservices

Postgres + RabbitMQ + gateway + workers with healthchecks and depends_on conditions

📋Configuration Files

docker-compose.yml

Full microservices stack with healthchecks, volumes, and internal service DNS

yaml
1version: "3.9"
2
3services:
4 postgres:
5 image: postgres:16-alpine
6 environment:
7 - POSTGRES_DB=urlshortener
8 - POSTGRES_USER=postgres
9 - POSTGRES_PASSWORD=postgres
10 ports:
11 - "5432:5432"
12 volumes:
13 - pg_data:/var/lib/postgresql/data
14 healthcheck:
15 test: ["CMD-SHELL", "pg_isready -U postgres"]
16 interval: 5s
17 timeout: 5s
18 retries: 20
19
20 rabbitmq:
21 image: rabbitmq:3.12-management-alpine
22 ports:
23 - "5672:5672"
24 - "15672:15672"
25 environment:
26 RABBITMQ_DEFAULT_USER: guest
27 RABBITMQ_DEFAULT_PASS: guest
28 healthcheck:
29 test: ["CMD", "rabbitmq-diagnostics", "ping"]
30 interval: 10s
31 timeout: 10s
32 retries: 10
33
34 gateway:
35 build: ./gateway
36 ports:
37 - "3002:3000"
38 environment:
39 PG_HOST: postgres
40 PG_DB: urlshortener
41 PG_USER: postgres
42 PG_PASSWORD: postgres
43 RABBIT_URL: amqp://guest:guest@rabbitmq:5672
44 BASE_URL: http://localhost:3002
45 depends_on:
46 postgres:
47 condition: service_healthy
48 rabbitmq:
49 condition: service_healthy
50
51 cache-worker:
52 build: ./cache-worker
53 environment:
54 RABBIT_URL: amqp://guest:guest@rabbitmq:5672
55 depends_on:
56 rabbitmq:
57 condition: service_healthy
58
59 analytics-worker:
60 build: ./analytics-worker
61 environment:
62 PG_HOST: postgres
63 PG_DB: urlshortener
64 PG_USER: postgres
65 PG_PASSWORD: postgres
66 RABBIT_URL: amqp://guest:guest@rabbitmq:5672
67 depends_on:
68 postgres:
69 condition: service_healthy
70 rabbitmq:
71 condition: service_healthy
72
73volumes:
74 pg_data:
📄

Step 01

Deploy Microservices Stack

(01)Start the full stack

Linux
1docker compose up -d --build
2docker compose ps
3# RabbitMQ UI: http://localhost:15672 (guest/guest)
4# API gateway: http://localhost:3002