Running stack of microservices using docker-compose and acim/go-reflex image

2021-10-23
Go microservice docker-compose docker

Go is very attractive language for microservices' development, but using acim/go-reflex image and docker-compose you can run multiple microservices including your gateway on your local machine. This image can run virtually any Go server based application and also reacts on changes in the code and recompiles the binary on the fly. If you want to debug your microservices' stack or develop a new feature where you have to touch multiple services, this is very good tool to do so. Let’s take a look at the docker-compose stack example:

version: '3.8'

services:
  postgres:
    container_name: my-postgres
    image: postgres:12
    restart: always
    environment:
      - POSTGRES_USER=me
      - POSTGRES_PASSWORD=pass
      - POSTGRES_DB=test
    ports:
      - 5432:5432
    volumes:
      - postgres:/var/lib/postgresql/data
  service-1:
    container_name: my-service-1
    image: acim/go-reflex
    restart: always
    depends_on:
      - postgres
    environment:
      - RACE_DETECTOR=1
      - MY_POSTGRES_HOST=postgres
      - MY_POSTGRES_USER=me
      - MY_POSTGRES_PASSWORD=pass
    ports:
      - 3001:3000
      - 50051:50051
    volumes:
      - ../my-service-1:/app
    stdin_open: true
    tty: true
  service-2:
    container_name: my-service-2
    image: acim/go-reflex
    restart: always
    depends_on:
      - service-1
    environment:
      - RACE_DETECTOR=1
      - MY_SERVICE_1_HOST=service-1
    ports:
      - 3002:3000
      - 50052:50051
    volumes:
      - ../my-service-2:/app
    stdin_open: true
    tty: true
  api-gw:
    container_name: my-api-gw
    image: acim/go-reflex
    restart: always
    depends_on:
      - service-1
      - service-2
    environment:
      - RACE_DETECTOR=1
      - MY_SERVICE_1_HOST=service-1
      - MY_SERVICE_2_HOST=service-2
    ports:
      - 8080:3000
    volumes:
      - .:/app
    stdin_open: true
    tty: true

volumes:
  postgres:

The stack above contains 4 images. We assume that the docker-compose.yml file lives in the root of the my-gw project and that other microservices exist at the same level as the API gateway, so they are in the same parent directory.

You can find further documentation here . All feature requests are welcome, just open an issue. It is important to say that the image is available for amd64 and arm64 architectures.

P.S. If you like the project, please star it on GitHub and Docker Hub . 🙂

Upcoming Go's generics

Find out more about upcoming generics in Go
Go Golang generics

Go vanity imports

Release your packages under custom domain using vanity imports
Go Golang

A first impression of Rust from the perspective of a Go developer

Rust is very powerful, but let's see how it compares to Go
Go Rust Kubernetes controller secret replicator