Go, gRPC and Docker

Mat Evans
5 min readJun 7, 2017

There are plenty of little snippets of info about Go and Docker. It really is very simple to create multiple containers, let them talk to each other, and let you talk to them. So here’s a little example of how it’s done.

What are we building?

We’re going to build a very simple gRPC client and server. The server will sit in a Docker container and serve requests from a simple client.

For some reason we need a service that reverses strings. Yes that’s right, I know what you’re thinking — that’s a genius idea! Well here’s how to do it.

The .proto file

As mentioned in an earlier article about gRPC we need to spec a .proto file to describe the service that we’re creating.

syntax = "proto3";package reverse;service Reverse {
rpc Do(Request) returns (Response) {}
}
message Request {
string message = 1;
}
message Response {
string message = 1;
}

Once we have the .proto file, we need to compile it to a .go file. This is as simple as using the following command. Note — you need to make sure you have protoc installed as well as gRPC.

$ protoc -I . reverse.proto --go_out=plugins=grpc:.

--

--