25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →

Running Locally with Docker-compose

April 22, 2021
Elliot Forbes

Elliot Forbes

Course Instructor

Hey Gophers! My name is Elliot and I'm the creator of TutorialEdge and I've been working with Go systems for roughly 5 years now.

Dockerfile

FROM golang:1.20 AS builder
RUN mkdir /app
ADD . /app
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build -o app cmd/server/main.go

FROM alpine:latest AS production
COPY --from=builder /app .
CMD ["./app"]

Docker-compose

version: "3.8"

services:
  db:
    image: postgres:12.2-alpine
    container_name: "database"
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
    networks:
      - fullstack
    volumes:
      - database_postgres:/var/lib/postgresql/data
  
  api:
    build: .
    container_name: "grpc-microservice"
    environment:
      DB_USERNAME: "postgres"
      DB_PASSWORD: "postgres"
      DB_DB: "postgres"
      DB_HOST: "db"
      DB_TABLE: "postgres"
      DB_PORT: "5432"
      DB_SSL_MODE: "disable"
    ports:
      - "50051:50051"
    depends_on:
      - db
    networks:
      - fullstack

volumes:
  database_postgres:

networks:
  fullstack:
    driver: bridge

Running Our App

$ docker-compose up --build