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:
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,
is really nice tool to debug your gRPC services. The RACE_DETECTOR environment variable is used by
acim/go-refleximage to turn on
go build --raceflag. The crucial part in the configuration is the volume. There we map
/appdirectory in the container. This will allow that
acim/go-refleximage works correctly and reacts to the changes in
../my-service-1and 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
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 . 🙂