This tutorial walks through deploying a simple Node.js "Hello World" app using Docker and Google Cloud Run. It covers writing the app, containerizing it, deploying via GCP CLI, and cleaning up resources.
Prerequisites:
- Basic understanding of Node.js
- Docker installed (if running locally)
- Access to Google Cloud Shell
- A Google Cloud Project with billing enabled
Step-by-Step Guide
Set Up Your Node.js App
Create a simple Express app in a file named index.js
the file I used can be found on link.Create the Dockerfile
In the same directory, create a file named Dockerfile with the following: or find link in
FROM node:12-slim
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
COPY . .
CMD ["npm", "start"]
This will install dependencies and start the app when the container runs.
- Build and Push the Docker Image Run this in Cloud Shell (replace $PROJECT_ID with your actual project ID):
gcloud builds submit --tag gcr.io/$PROJECT_ID/helloworld
- Deploy to Cloud Run
gcloud run deploy helloworld \
--image gcr.io/$PROJECT_ID/helloworld \
--platform managed \
--region us-east4 \
--allow-unauthenticated
The service will be deployed and you'll receive a URL to access it.
App is live: https://helloworld-xxxxxxxxxx-xx.run.app
- clean up resources Once you're done testing:
Delete the Cloud Run service
gcloud run services delete helloworld --region=us-east4
Delete the Docker image:
gcloud container images delete gcr.io/$PROJECT_ID/helloworld
Top comments (0)