How to run on Cloud Run

This describes how to set up the Dockerized gRPC server to run on Google Cloud Run, while the clients are training the model locally. We assume that the Docker container$GCP_PROJECT/appfl-test:latest is already available. If you are not sure, see Preparing a Docker container.

Deploying the Dockerized gRPC server

The Docker container can be deployed to the cloud, and the communication port will be open at 50051. The port should be set to the same as in the appfl configuration.

gcloud beta run deploy appfl-test \
--execution-environment gen2 \
--image$GCP_PROJECT/appfl-test:latest \
--platform managed \
--memory=4G \
--port=50051 \
--command=python3 \ \
--args="--logging=INFO" \

The last four arguments replace the default CMD in Dockerfile, and thus may have values of your choice. If the package is successfully deployed to the cloud, you may see the messages like this:

Deploying container to Cloud Run service [appfl-test] in project [grpc-tutorial-123456] region [us-central1] Deploying new service... Done.
   Creating Revision...
   Routing traffic...
   Setting IAM Policy...
Service [appfl-test] revision [appfl-test-00001-yif] has been deployed and is serving 100 percent of traffic.
Service URL:

Now the server is ready to listen requests from clients. The service URL is given in the last line from the above:, and this needs to be used as host when launching clients.

Launching a client

A client can start the federated learning with the following:

python \
--host=/ \
--use_tls=True \
--client_id=1 \


In this example we pass multiple arguments. The most important one is --host and --use_tls for the service URL and the indication of using TLS (transport layer security). Note that the port number is not passed.