5

I was wondering how people tend to share proto files between clients and servers in docker composites? I'm testing out gRPC for fun and created a project with the following layout:

docker-compose.yml
front/Dockerfile
      ...
back/Dockerfile
     proto/
     ...

Here front is the gRPC client to the back server. Now back/proto contains the protobuf files that I need for generating the client stub. The problem here is that this is outside the context for front. Anyone who uses these have any best practices to share for handling this?

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
Edvard Fagerholm
  • 862
  • 5
  • 15

1 Answers1

0

I have two options for you:

Docker Multistage Build

You could use a docker multi-stage build. Generate the back docker container first, then use multi-stage build to pull the .proto files from the back container to the front container.

The front container Dockerfile could look something like:

FROM back AS builder

FROM alpine:latest  
COPY --from=builder proto/ proto/
...other commands...

Extended Build Context

Another option would be to issue the docker build command from the directory above:

docker build -f back/Dockerfile .
docker build -f front/Dockerfile .

This would extend the build context to include both front and back directories. That way you could just reference back/proto/ in your front Dockerfile.

JGC
  • 5,725
  • 1
  • 32
  • 30