On Debian/Ubuntu, the protobuf-compiler package ships the protoc binary but not the “well-known type” .proto files (google/protobuf/timestamp.proto, wrappers.proto, any.proto, …). Any tonic/prost build whose .proto files import a well-known type will fail at compile time in the image unless you also install libprotobuf-dev.

For Agents

Building a Docker/CI image for a Rust gRPC service (tonic-build / prost-build in build.rs)? If any vendored .proto imports google/protobuf/*, install both protobuf-compiler and libprotobuf-dev. The second package is what drops the WKT .proto sources into /usr/include/google/protobuf/ where protoc looks for imports. Found building the solv1-rig image.

Symptom

Local cargo build works (your machine has a full protobuf install), but the Docker/CI build fails in build.rs with something like:

Import "google/protobuf/timestamp.proto" was not found or had errors.

or a tonic-build/prost-build panic unwrapping the compile_protos result.

Root Cause

protoc resolves import statements against its include path. The stock protobuf-compiler apt package installs only the compiler binary; the well-known-type descriptors (the .proto files under google/protobuf/) live in the separate libprotobuf-dev package. Without it, protoc has the compiler but nothing to resolve import "google/protobuf/…" against, so any proto that imports a WKT — directly or transitively — won’t compile.

This bites any tonic/prost image the moment a vendored proto pulls in a WKT. It does not reproduce locally when your dev box has a complete protobuf toolchain, so it surfaces first in the container build.

Fix

Install both packages in the builder stage:

RUN apt-get update && apt-get install -y --no-install-recommends \
        protobuf-compiler \
        libprotobuf-dev \
    && rm -rf /var/lib/apt/lists/*

Quick checks

  • dpkg -L libprotobuf-dev | grep timestamp.proto should list /usr/include/google/protobuf/timestamp.proto once installed.
  • Alternatively, prost/tonic can bundle a vendored protoc via the protoc feature / protoc-bin-vendored, sidestepping the system package entirely — but if you rely on the apt protoc, you need libprotobuf-dev alongside it.