Accéder au contenu principal

Actualisé 13 mars 2025  · 9 min de lecture

 

mkdir hello-world-app
cd hello-world-app
const http = require('http');

const requestListener = (req, res) => {
    res.writeHead(200);
    res.end('Hello, Cloud Run!');
};

const server = http.createServer(requestListener);
server.listen(8080, () => {
    console.log('Server is running on port 8080');
});
{
    "name": "hello-world-app",
    "version": "1.0.0",
    "main": "index.js",
    "dependencies": {}
}

# Use the official Node.js image as a base
FROM node:16-alpine

# Set the working directory inside the container
WORKDIR /usr/src/app

# Copy package.json and install dependencies (if any)
COPY package*.json ./

# Copy the rest of the application code
COPY . .

# Expose port 8080 for Cloud Run
EXPOSE 8080

# Start the app
CMD ["node", "index.js"]

docker build -t gcr.io/your-project-id/hello-world-app .

docker run -p 8080:8080 gcr.io/your-project-id/hello-world-app

gcloud services enable artifactregistry.googleapis.com

gcloud artifacts repositories create hello-world-repo \
--repository-format=docker \
--location=us-central1

gcloud auth configure-docker us-central1-docker.pkg.dev

docker tag gcr.io/your-project-id/hello-world-app us-central1-docker.pkg.dev/your-project-id/hello-world-repo/hello-world-app

docker push us-central1-docker.pkg.dev/your-project-id/hello-world-repo/hello-world-app

gcloud run deploy hello-world-app \
--image us-central1-docker.pkg.dev/your-project-id/hello-world-repo/hello-world-app \
--platform managed \
--region us-central1 \
--allow-unauthenticated
  • us-central1-docker.pkg.dev/your-project-id/hello-world-repo/hello-world-app:

1.

gcloud run services delete hello-world-app --region us-central1

2.

gcloud artifacts docker images list us-central1-docker.pkg.dev/your-project-id/hello-world-repo
gcloud artifacts docker images delete us-central1-docker.pkg.dev/your-project-id/hello-world-repo/hello-world-app --delete-tags

3.

gcloud artifacts repositories delete hello-world-repo --location=us-central1

4.

gcloud projects delete your-project-id

gcloud run deploy hello-world-app \
--source . \
--region us-central1 \
--allow-unauthenticated

1.

2.

3.

4.

5.

Google Cloud

Google Cloud

Google Cloud

Google Cloud

 

CPU

 

Conclusion


Marie Fayard's photo
Author
Marie Fayard

Ingénieur logiciel senior, rédacteur technique et conseiller avec une formation en physique. Nous nous engageons à aider les jeunes entreprises à atteindre leur potentiel et à rendre des concepts complexes accessibles à tous.

Sujets
Certification disponible

Cours

2 hr
135K
Afficher les détailsRight Arrow
Commencer le cours
Voir plusRight Arrow