Run protoc command into docker container Run protoc command into docker container docker docker

Run protoc command into docker container


The easiest way to get non-default tools like this is to install them through the underlying Linux distribution's package manager.

First, look at the Docker Hub page for the node image. (For "library" images like node, construct the URL https://hub.docker.com/_/node.) You'll notice there that there are several variations named "alpine", "buster", or "stretch"; plain node:12 is the same as node:12-stretch and node:12.20.0-stretch. The "alpine" images are based on Alpine Linux; the "buster" and "stretch" ones are different versions of Debian GNU/Linux.

For Debian-based packages, you can then look up the package on https://packages.debian.org/ (type protoc into the "Search the contents of packages" form at the bottom of the page). That leads you to the protobuf-compiler package. Knowing that contains the protoc binary, you can install it in your Dockerfile with:

FROM node:12 # Debian-basedRUN apt-get update \ && DEBIAN_FRONTEND=noninteractive \    apt-get install --no-install-recommends --assume-yes \      protobuf-compiler# The rest of your Dockerfile as aboveCOPY ...RUN protoc ...

You generally must run apt-get update and apt-get install in the same RUN command, lest a subsequent rebuild get an old version of the package cache from the Docker build cache. I generally have only a single apt-get install command if I can manage it, with the packages list alphabetically one to a line for maintainability.

If the image is Alpine-based, you can do a similar search on https://pkgs.alpinelinux.org/contents to find protoc, and similarly install it:

FROM node:12-alpineRUN apk add --no-cache protoc# The rest of your Dockerfile as above


Finally I solved my own issue.

The problem was the arch version: I was using linux-x86_32.zip but works using linux-x86_64.zip

Even @David Maze answer is incredible and so complete, it didn't solve my problem because using apt-get install version 3.0.0 and I wanted 3.14.0.

So, the Dockerfile I have used to run protoc into a docker container is like this:

FROM node:12... # Download proto zipENV PROTOC_ZIP=protoc-3.14.0-linux-x86_64.zipRUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/${PROTOC_ZIP}RUN unzip -o ${PROTOC_ZIP} -d ./proto RUN chmod 755 -R ./proto/binENV BASE=/usr# Copy into pathRUN cp ./proto/bin/protoc ${BASE}/bin/RUN cp -R ./proto/include/* ${BASE}/include/# Download protoc-gen-grpc-webENV GRPC_WEB=protoc-gen-grpc-web-1.2.1-linux-x86_64ENV GRPC_WEB_PATH=/usr/bin/protoc-gen-grpc-webRUN curl -OL https://github.com/grpc/grpc-web/releases/download/1.2.1/${GRPC_WEB}# Copy into pathRUN mv ${GRPC_WEB} ${GRPC_WEB_PATH}RUN chmod +x ${GRPC_WEB_PATH}RUN protoc -I=...