Skip to content

Commit 3879ec2

Browse files
authored
Merge pull request #191 from LAA-Software-Engineering/fix/136-compose-pins-volumes
chore(compose): pin images, localhost binds, Postgres volume (#136)
2 parents b6fb79f + a4a9199 commit 3879ec2

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ clean:
4646
docker rm dockerPostgres
4747
docker rm dockerRedis
4848
docker image rm golang-rest-api-template-backend
49+
# Legacy bind-mount dir (Compose now uses named volume postgres_data).
4950
rm -rf .dbdata

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ To generate URL-safe random values for `JWT_SECRET_KEY` and `API_SECRET_KEY`, ru
139139
go run ./scripts/generate_key.go
140140
```
141141

142-
`docker-compose.yml` does **not** embed JWT or API secrets; they must come from `.env` or your shell environment so keys are not committed to the repository. The Compose file sets **`GIN_MODE=release`** for the API service so production-style security headers apply; override in `.env` if you need `debug` locally.
142+
`docker-compose.yml` does **not** embed JWT or API secrets; they must come from `.env` or your shell environment so keys are not committed to the repository. The Compose file sets **`GIN_MODE=release`** for the API service so production-style security headers apply; override in `.env` if you need `debug` locally. Service images use **pinned tags** (Postgres, Redis, Mongo), **published ports bind to `127.0.0.1`** for local dev, and Postgres data uses a **named volume** (`postgres_data`, same pattern as `mongo_data`). Remove volumes with `docker compose down -v` when you want a fresh database.
143143

144144
### API Documentation
145145

docker-compose.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
context: .
66
dockerfile: Dockerfile
77
ports:
8-
- 8001:8001
8+
- "127.0.0.1:8001:8001"
99
depends_on:
1010
db:
1111
condition: service_healthy
@@ -28,14 +28,14 @@ services:
2828
GIN_MODE: release
2929

3030
db:
31-
image: postgres:14.1-alpine
31+
image: postgres:14.17-alpine
3232
restart: always
3333
container_name: dockerPostgres
3434
volumes:
35-
# Official postgres image stores cluster data under PGDATA (default /var/lib/postgresql/data).
36-
- .dbdata:/var/lib/postgresql/data
35+
# Named volume (aligned with mongo_data); avoids bind-mounting ./.dbdata into the image context.
36+
- postgres_data:/var/lib/postgresql/data
3737
ports:
38-
- "5435:5435"
38+
- "127.0.0.1:5435:5435"
3939
environment:
4040
- POSTGRES_DB=go_app_dev
4141
- POSTGRES_USER=docker
@@ -49,9 +49,9 @@ services:
4949
start_period: 10s
5050

5151
redis:
52-
image: "redis:alpine"
52+
image: redis:7.4.2-alpine
5353
ports:
54-
- "6379:6379"
54+
- "127.0.0.1:6379:6379"
5555
container_name: dockerRedis
5656
healthcheck:
5757
test: ["CMD", "redis-cli", "ping"]
@@ -61,12 +61,12 @@ services:
6161
start_period: 5s
6262

6363
mongo:
64-
image: mongo
64+
image: mongo:7.0.15
6565
container_name: dockerMongo
6666
volumes:
6767
- mongo_data:/data/db
6868
ports:
69-
- "27017:27017"
69+
- "127.0.0.1:27017:27017"
7070
restart: always
7171
healthcheck:
7272
test: ["CMD", "mongosh", "--quiet", "--eval", "db.runCommand({ ping: 1 }).ok"]
@@ -76,4 +76,5 @@ services:
7676
start_period: 10s
7777

7878
volumes:
79-
mongo_data: # Declare the volume for MongoDB data
79+
mongo_data:
80+
postgres_data:

0 commit comments

Comments
 (0)