Based on https://github.com/haunt98/docker-protoc
Run protoc
with docker
.
- Go
From Docker Hub
docker pull safebike/protoc
Or with the makefile
make build IMAGE=image TAG=tag
make example
This will generate gRPC code of hello/hello.proto
with protoc
and regenerate the hello/hello.pb.go
and hello/hello_grpc.pb.go
files, which contain:
- Code for populating, serializing, and retrieving HelloRequest and HelloReply message types.
- Generated client and server code.
/home/docker/app
is mount point in docker container, because user is docker
not root
.
/home/docker/.local/include
, /home/docker/.local/include/third_party/googleapis
is where to store imported proto files.
Need to replace /path/to/output
, /path/to/proto
with your path.
Need to replace image
, tag
with your docker image, tag.
With buf
:
Should include buf.yaml file.
docker run --rm --volume $(pwd):/home/docker/app --workdir /home/docker/app image:tag \
protoc \
-I /home/docker/.local/include \
-I /home/docker/.local/include/third_party/googleapis \
-I . \
--buf-check-lint_out . \
/path/to/proto
docker run --rm --volume $(pwd):/home/docker/app --workdir /home/docker/app image:tag \
protoc \
-I /home/docker/.local/include \
-I /home/docker/.local/include/third_party/googleapis \
-I . \
--go_out /path/to/output \
--go-grpc_out /path/to/output \
/path/to/proto
With grpc-gateway
:
docker run --rm --volume $(pwd):/home/docker/app --workdir /home/docker/app image:tag \
protoc \
-I /home/docker/.local/include \
-I /home/docker/.local/include/third_party/googleapis \
-I . \
--go_out /path/to/output \
--go-grpc_out /path/to/output \
--grpc-gateway_out /path/to/output \
--grpc-gateway_opt logtostderr=true \
--swagger_out /path/to/output \
--swagger_out logtostderr=true \
/path/to/proto
Should include .clang-format file.
docker run --rm --volume $(pwd):/home/docker/app --workdir /home/docker/app image:tag \
clang-format -i \
/path/to/proto