Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Déployer une application Cloud Run à l'aide de Cloud Shell
Découvrez comment configurer et déployer un exemple d'application Hello World dans Cloud Run et afficher l'état des ressources de votre service actif.
Avant de commencer
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Dans la barre d'état Cloud Code, sélectionnez New Application (Nouvelle application).
Sélectionnez Application Cloud Run comme type d'application préféré.
Dans la liste des exemples d'applications (Node.js, Python avec frameworks Flask et Django, Java, Go), choisissez une application Hello World.
Par exemple, si vous sélectionnez Python (Flask): Hello World, une application Hello World de démarrage en langage Python (Flask) est créée.
Sélectionnez un dossier comme emplacement pour l'application, puis cliquez sur Créer une application.
L'éditeur Cloud Shell charge l'application dans un nouvel espace de travail.
Une fois l'espace de travail chargé, votre application est accessible dans la vue de l'explorateur.
Déployer dans Cloud Run
Pour déployer votre application sur Cloud Run, procédez comme suit :
Ouvrez la palette de commandes (appuyez sur Ctrl/Cmd+Shift+P ou cliquez sur Affichage > Palette de commandes), puis exécutez la commande Deploy to Cloud Run (Déployer sur Cloud Run). L'interface utilisateur de déploiement Cloud Run s'affiche.
Si vous y êtes invité, autorisez Cloud Code à effectuer les appels d'API Google Cloud .
Définissez votre projet Google Cloud .
Si vous y êtes invité, activez l'API Cloud Run en cliquant sur Enable APIs (Activer les API).
Dans la boîte de dialogue "Deploy to Cloud Run" (Déployer sur Cloud Run), sélectionnez un service préexistant ou créez-en un.
Si vous créez un service, sélectionnez Cloud Run (entièrement géré) sous "Plate-forme de déploiement".
Choisissez une région dans laquelle effectuer le déploiement.
Pour l'authentification, sélectionnez Allow unauthenticated invocations (Autoriser les appels non authentifiés) pour rendre ce service public.
Après avoir défini vos préférences, vous pouvez cliquer sur Déployer.
Cloud Code crée ensuite votre image, la transfère dans le registre et déploie votre application dans Cloud Run. Votre service est désormais actif !
Affichez le service en cours d'exécution en suivant l'URL affichée dans la boîte de dialogue "Cloud Run: Deploy" (Cloud Run : Déployer).
Modifier votre service
Pour modifier votre application, procédez comme suit :
Dans la vue de l'explorateur, recherchez le fichier app.py qui met en œuvre le comportement du service.
Remplacez le message "It's running!" (En cours d'exécution) par le message de votre choix.
Une fois cette modification effectuée, choisissez la commande Deploy to Cloud Run (Déployer sur Cloud Run) à l'aide de la palette de commandes.
Vérifiez que le service que vous venez de créer est sélectionné dans "Service Settings" (Paramètres du service).
Cliquez sur Déployer.
Une fois votre application créée et déployée, vous pouvez actualiser votre service pour afficher le message mis à jour.
Afficher les journaux
Vous pouvez également afficher les journaux de votre application déployée avec la visionneuse de journaux fournie avec Cloud Code.
Pour afficher les journaux, procédez comme suit :
Cliquez sur Cloud Code, puis développez la section Cloud Run.
Faites un clic droit sur votre service Cloud Run, puis cliquez sur Afficher les journaux.
Actualisez votre application dans le navigateur, puis cliquez sur le bouton d'actualisation des journaux afin de consulter les nouveaux journaux générés.
Effectuer un nettoyage
Pour éviter que les ressources utilisées sur cette page soient facturées sur votre compte Google Cloud , procédez comme suit :
Pour supprimer votre projet :
Accédez à la page "Projets" de la console Google Cloud :
Sélectionnez le projet que vous avez créé dans ce guide de démarrage rapide, puis cliquez sur Supprimer.
Cette opération ferme le projet et programme sa suppression.
Si vous utilisez un projet préexistant et que vous souhaitez supprimer les ressources que vous avez créées pour ce démarrage rapide :
Image du conteneur : bien que Cloud Run ne facture pas lorsqu'un service n'est pas utilisé, il se peut que des frais vous soient facturés pour le stockage de l'image de conteneur dans Artifact Registry.
Pour supprimer votre image, ouvrez la page Artifact Registry, sélectionnez le dépôt contenant votre image, sélectionnez votre image, puis cliquez sur Supprimer, et à nouveau sur Supprimer.
Service Cloud Run : pour supprimer un service Cloud Run, sélectionnez le service à supprimer sur la page Cloud Run de la consoleGoogle Cloud , puis cliquez sur Supprimer, puis sur Supprimer.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[],[],null,["# Quickstart: Deploy a Cloud Run service by using Cloud Shell\n\nDeploy a Cloud Run app by using Cloud Shell\n===========================================\n\nLearn how to set up and deploy a sample Hello World application to\nCloud Run and view the status of your live service's resources.\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\nCreate an application\n---------------------\n\n1. [Launch the Cloud Shell Editor](https://ide.cloud.google.com).\n2. From the Cloud Code status bar, select **New Application**.\n3. Choose **Cloud Run application** as your preferred application type.\n4. From the list of sample applications (Node.js, Python with Flask and Django\n frameworks, Java, Go), choose a Hello World app.\n\n For example, choosing `Python (Flask): Hello World` creates a starter\n Python (Flask) Hello World app.\n5. Select a folder as your application location and then click\n **Create New Application**.\n\n Cloud Shell Editor loads the application in a new workspace.\n After the workspace loads, your app is accessible in the explorer view.\n\nDeploy to Cloud Run\n-------------------\n\nTo deploy your application to Cloud Run, follow these steps:\n\n1. Open the command palette (press `Ctrl`/`Cmd`+`Shift`+`P` or click **View** \\\u003e **Command Palette** ) and then run the **Deploy to Cloud Run** command. This brings up the Cloud Run Deploy UI.\n2. If prompted, authorize Cloud Code to make Google Cloud API calls.\n3. Set your Google Cloud project.\n4. If prompted, enable the Cloud Run API by clicking **Enable APIs**.\n5. In the Deploy to Cloud Run dialog, select a pre-existing service or create a new one.\n6. If you're creating a new service, choose **Cloud Run (fully managed)** under Deployment Platform.\n7. Choose a region to deploy to.\n8. For Authentication, select **Allow unauthenticated invocations** to make this a public service.\n9. After you define your preferred settings, you can click **Deploy**.\n\n Cloud Code builds your image, pushes it to the registry, and\n deploys your app to Cloud Run. Your service is now live!\n10. View your running service by following the URL displayed in\n your Cloud Run: Deploy dialog.\n\nEdit your service\n-----------------\n\nTo edit your application, follow these steps:\n\n1. With the Explorer view, find the `app.py` file that implements the service behavior.\n2. Change the message \"It's running!\" to a message of your choosing.\n3. After you make this change, choose the **Deploy to Cloud Run** command using the Command Palette.\n4. Check that the service you just created is selected in Service Settings.\n5. Click **Deploy**.\n6. After your application finishes building and deploying, you can refresh your service to see your updated message.\n\nView logs\n---------\n\nYou can also view logs from your deployed application with the Log Viewer\nthat comes with Cloud Code.\n\nTo view logs, follow these steps:\n\n1. Click **Cloud\n Code** and then expand the **Cloud Run** section.\n2. Right-click your Cloud Run service and then click **View logs**.\n\n3. Refresh your app in the browser, and see the new logs generated by\n clicking the Logs refresh button.\n\nClean up\n--------\n\n\nTo avoid incurring charges to your Google Cloud account for\nthe resources used on this page, follow these steps.\n\nTo delete your project:\n\n1. Go to the Projects page in the Google Cloud console:\n\n [Go to the Projects page](https://console.cloud.google.com/project)\n2. Select the project you created for this quickstart and then click\n **Delete**.\n\n This shuts down the project and schedules it for deletion.\n\nIf you're using a pre-existing project and would like to delete resources\nyou created for this quickstart:\n\n- **Container image:** While Cloud Run doesn't charge when a\n service isn't in use, you might still be\n [charged for storing the container image in Artifact Registry](/artifact-registry/pricing).\n To delete your image, open the Artifact Registry page, select the\n repository that contains your image, select your image, click **Delete** ,\n and then click **Delete**.\n\n [Open the Artifact Registry page](https://console.cloud.google.com/artifacts)\n- **Cloud Run service:** To delete a Cloud Run\n service, from the Cloud Run page in the\n Google Cloud console, select the service you'd like to delete, click\n **Delete** , and then click **Delete**.\n\n [Open the Cloud Run page](https://console.cloud.google.com/run)\n\nWhat's next\n-----------\n\n- Discover the variety of features that the [Cloud Shell Editor interface](/shell/docs/editor-overview) has to offer.\n- Learn how to [configure Cloud Shell](/shell/docs/configuring-cloud-shell) to customize your experience."]]