Cloud Run runs stateless containers on a fully managed environment or in your own GKE cluster.
Sample | Description | Deploy |
---|---|---|
Hello World ➥ | Quickstart | |
System Packages | Use system-installed binaries in your service. | |
Pub/Sub | Event-driven service with a Pub/Sub push subscription | |
Image Processing | Event-driven image analysis & transformation | |
Manual Logging | Structured logging without client library | |
Cloud SQL (MySQL) | Use MySQL with Cloud Run | - |
Cloud SQL (Postgres) | Use Postgres with Cloud Run | - |
Hello Broken | Something is wrong, how do you fix it? |
For more Cloud Run samples beyond Node.js, see the main list in the Cloud Run Samples repository.
-
Clone this repository:
git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
Note: Some samples in the list above are hosted in other repositories. They are noted with the symbol "➥".
-
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
Opening a shell in the container (e.g., updating the
package-lock.json
):-
Build the container.
-
Run the container with a shell:
PORT=8080 && docker run --rm \ --interactive --tty \ -p 8080:${PORT} -e PORT=${PORT} \ -v $PWD:/usr/src/app $SAMPLE \ /bin/bash
- Re-generate the
package-lock.json
:
rm package-lock.json npm install
Because we're using a read/write volume mount, the revised file will be written to the host's local filesystem. Once you exit the container you can add the file to version control.
- Exit the container:
Ctrl-D
-
gcloud builds submit --tag gcr.io/${GOOGLE_CLOUD_PROJECT}/${SAMPLE}
gcloud run deploy $SAMPLE \
# Needed for Manual Logging sample.
--set-env-var GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT} \
--image gcr.io/${GOOGLE_CLOUD_PROJECT}/${SAMPLE}
See Building containers and Deploying container images for more information.