Cloud Run runs stateless containers on a fully managed environment or in your own GKE cluster.
Sample | Description | Deploy |
---|---|---|
Hello World | Quickstart |
For more Cloud Run samples beyond Ruby, see the main list in the Cloud Run Samples repository.
-
Clone this repository:
git clone https://github.com/GoogleCloudPlatform/ruby-docs-samples.git
-
Create an Artifact Registry:
gcloud artifacts repositories create containers --repository-format docker --location ${GOOGLE_CLOUD_REGION}
-
# Replace <sample> with the sample name, ie 'helloworld' export SAMPLE=<sample> cd $SAMPLE docker build --tag $SAMPLE .
-
With the built container:
PORT=8080 && docker run --rm -p 8080:${PORT} -e PORT=${PORT} $SAMPLE
Overriding the built container with local code:
PORT=8080 && docker run --rm \ -p 8080:${PORT} -e PORT=${PORT} \ -v $PWD:/usr/src/app $SAMPLE
Injecting your service account key:
export SA_KEY_NAME=my-key-name-123 PORT=8080 && docker run --rm \ -p 8080:${PORT} -e PORT=${PORT} \ -e GOOGLE_APPLICATION_CREDENTIALS=/tmp/keys/${SA_KEY_NAME}.json \ -v $GOOGLE_APPLICATION_CREDENTIALS:/tmp/keys/${SA_KEY_NAME}.json:ro \ -v $PWD:/usr/src/app $SAMPLE
-
Visit the application at http://localhost:8080.
-
Set your GCP project Id:
export GOOGLE_CLOUD_PROJECT=$(gcloud config get-value project)
-
Build your container image using Cloud Build, by running the following command from the directory containing the Dockerfile:
gcloud builds submit --tag ${GOOGLE_CLOUD_REGION}-docker.pkg.dev/${GOOGLE_CLOUD_PROJECT}/containers/${SAMPLE}
-
Deploy the container image using the following command:
gcloud run deploy ${SAMPLE} \ --image ${GOOGLE_CLOUD_REGION}-docker.pkg.dev/${GOOGLE_CLOUD_PROJECT}/containers/${SAMPLE}
See Building containers and Deploying container images for more information.