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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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.

  • In the first image we setup PostgreSQL database as our hypothetical dependency. We map it to host port 5432 so that we can access the data for debugging purposes.
  • Then we configure our service-1. We assume it depends on postgres and it serves REST on port 3000 and gRPC on port 50051. We map these ports to host ports 3001 and 50051 respectively also for debugging purposes. By the way, wombat is really nice tool to debug your gRPC services. The RACE_DETECTOR environment variable is used by acim/go-reflex image to turn on go build --race flag. The crucial part in the configuration is the volume. There we map ../my-service-1 to /app directory in the container. This will allow that acim/go-reflex image works correctly and reacts to the changes in ../my-service-1 and recompiles and restarts the binary.
  • In the next step we configure our service-2 where we also assume that it also talks REST and gRPC so we map these to ports 3002 and 50051 on the host. Now we map the volume to ../my-service-2, the location of our other microservice. Our application probably needs to know the location of my-service-1 which we pass using MY_SERVICE_1_HOST environment variable.
  • Finally we configure the API gateway application which is our exposed service which talks to SPA, for example. Again nothing special there, everything works just by magic of acim/go-reflex.

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 . 🙂