🐹
Docker Compose

Go App + MongoDB Compose

Go API with MongoDB — DevOps-Pipeline-Go Minikube/docker-compose pattern

📋Configuration Files

docker-compose.yml

yaml
1version: "3"
2
3services:
4 app:
5 build: .
6 ports:
7 - "8080:8080"
8 depends_on:
9 - db
10 environment:
11 SERVER_PORT: 8080
12 MONGO_URI: mongodb://db:27017
13 security_opt:
14 - no-new-privileges:true
15
16 db:
17 image: mongo:latest
18 restart: always
19 ports:
20 - "27017:27017"
21 security_opt:
22 - no-new-privileges:true

Dockerfile

dockerfile
1FROM golang:1.22-alpine AS builder
2WORKDIR /app
3COPY go.mod go.sum ./
4RUN go mod download
5COPY . .
6RUN CGO_ENABLED=0 go build -o server .
7
8FROM alpine:3.19
9WORKDIR /app
10COPY --from=builder /app/server .
11EXPOSE 8080
12CMD ["./server"]
📄

Step 01

Run the Stack

(01)Build and start

Linux
1docker compose up -d --build
2docker compose ps
3curl http://localhost:8080/health