This is an example to run gRPC server on docker as well as access the server from a client on a local machine. Those files in the repository derives from an official example.
- Docker
- Anaconda
- Make
- Define the protocol-buffer in
helloworld.proto
. - Implement a command to generate python files from
helloworld.proto
incodegen.py
. - Implement
grpc_server.py
. - Implement
greeter_server.py
.
The command creates an anaconda environment.
We can activate the environment with source activate grpc-example
, since the environment name is grpc-example
.
make create-conda
# If you would like to remove the anaconda envronment,
make delete-conda
python grpc_server.py
python greeter_client.py
Greeter client received: Hello, cool guy!
The docker image is used for running grpc_server.py
.
The host name depends on your environment.
If you use docker-machine
, we can see the IP address with docker-machine ip YOUR_DOCKER_MACHINE
.
make build-docker
make run-docker
And then, we check if the client can access the server on docker or not:
# Execute it on your local machine, not a docker container.
python greeter_cliept.py --host HOST_NAME --port 50051