First, build a docker container that contains all required packages. In this example, I choose ubuntu:bionic as the basic image, and I installed other packages onto it.
FROM ubuntu:bionic RUN apt-get update RUN apt-get install python3 -y RUN apt-get install python3-pip -y RUN pip3 install grpcio ADD app /app/ EXPOSE 22222 The Dockerfile is shown above. In the app file, it contains 4 files. They are:
client.py, server.py, test_pb2.py, test_pb2_grpc.py
test_pb2.py and test_pb2_grpc.py is generated by compiling the test.protofile. The content for test.proto is shown below.
syntax = "proto3"; package lmjwtest; // service, encode a plain text service EncodeService { // request a service of encode rpc GetEncode(plaintext) returns (encodetext) {} } message plaintext { string pttransactionID = 1; string ptproperties = 2; string ptsenderID = 3; } message encodetext { string enctransactionID = 1; string encproperties = 2; string encsenderID = 3; } By using the grpcio-tools to compile the test.