Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Vous pouvez activer le mode de débogage pour une VM. En mode débogage, les comptes principaux disposant des rôles "Propriétaire", "Éditeur" et "Administrateur App Engine" sur le projet disposent d'un accès root à la VM. Lorsque le mode de débogage est activé, le déploiement automatique des mises à jour du système d'exploitation et des correctifs de sécurité est désactivé. En revanche, la VM fait toujours partie du pool d'équilibreur de charge et continue de recevoir des requêtes externes.
Chaque fois que vous activez ou désactivez le débogage, un événement "Activer/Désactiver le débogage des instances de VM" s'affiche dans la console Google Cloud et il est enregistré dans le fichier /var/log/syslog.log de la VM.
Activer et désactiver le mode de débogage
Vous pouvez utiliser l'outil gcloud afin d'activer et de désactiver le mode de débogage pour une instance. Pour déboguer une instance, votre rôle doit contenir l'autorisation appengine.instances.enableDebug.
Pour activer et désactiver le mode de débogage dans l'outil gcloud, procédez comme suit :
Exécutez la commande enable-debug app instances gcloud pour déboguer les VM d'une instance et d'une version particulières, comme ci-dessous :
Suivez ensuite les instructions pour spécifier la version de l'instance.
Lorsque vous désactivez le mode de débogage, la VM s'arrête, puis une nouvelle instance de votre application démarre et s'exécute sur une nouvelle VM propre.
Se connecter à l'instance
Console
Pour se connecter à une instance dans la console, procédez comme suit :
Consultez la page Google Cloud Instances de la console de votre projet:
Cliquez sur SSH tout à droite de la ligne contenant l'instance à laquelle vous souhaitez accéder :
L'instance passe alors en mode de débogage. Une session SSH s'ouvre pour l'instance dans une fenêtre de terminal.
Pour démarrer une session SSH, vous pouvez également sélectionner différentes options dans la liste déroulante.
À ce stade, vous utilisez l'hôte de l'instance, qui exécute plusieurs conteneurs. Pour en savoir plus sur les conteneurs, consultez la section ci-dessous intitulée Comprendre les principaux conteneurs.
Dans la fenêtre de terminal, répertoriez les conteneurs exécutés dans l'instance :
sudo docker ps
Le résultat de la commande sudo docker ps répertorie chaque conteneur par ligne. Recherchez la ligne contenant votre ID de projet : il s'agit du conteneur qui exécute votre code. Notez le NOM de ce conteneur.
(Facultatif) Vous pouvez afficher les informations de journalisation de votre application en appelant la commande suivante :
sudo docker logs CONTAINER-NAME
Démarrez un shell dans le conteneur qui exécute le code :
sudo docker exec -it CONTAINER-NAME /bin/bash
Une fois le débogage terminé, saisissez exit pour quitter le conteneur, puis saisissez de nouveau exit pour quitter la session SSH.
Désactivez le débogage de l'instance pour lui permettre de reprendre un fonctionnement normal.
gcloud
Pour vous connecter à une instance à l'aide de la commande gcloud, procédez comme suit :
gcloud beta app instances --project PROJECT-ID ssh INSTANCE-NAME --service SERVICE --version VERSION
À ce stade, vous utilisez l'hôte de l'instance, qui exécute plusieurs conteneurs.
Pour en savoir plus sur les conteneurs, consultez la section ci-dessous intitulée Comprendre les principaux conteneurs.
Dans la fenêtre de terminal, répertoriez les conteneurs exécutés dans l'instance :
sudo docker ps
Le résultat de la commande sudo docker ps répertorie chaque conteneur par ligne. Recherchez la ligne contenant votre ID de projet : il s'agit du conteneur qui exécute votre code. Notez le NOM de ce conteneur.
(Facultatif) Vous pouvez afficher les informations de journalisation de votre application en appelant la commande suivante :
sudo docker logs CONTAINER-NAME
Démarrez un shell dans le conteneur qui exécute le code :
docker exec -it CONTAINER-NAME /bin/bash
Une fois le débogage terminé, saisissez exit pour quitter le conteneur, puis saisissez de nouveau exit pour quitter la session SSH.
Désactivez le débogage de l'instance pour lui permettre de reprendre un fonctionnement normal.
Comprendre les principaux conteneurs
En plus du conteneur exécutant le code de votre application, votre instance peut également comporter les conteneurs ci-dessous :
Collecte, stocke et surveille les informations système.
Notez que ces conteneurs side-car sont susceptibles d'être modifiés sans préavis.
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)."],[[["\u003cp\u003eDebug mode provides root access to VMs for users with Owner, Editor, or App Engine Admin roles, but disables automatic OS updates and security patches temporarily.\u003c/p\u003e\n"],["\u003cp\u003eEnabling or disabling debug mode is logged in the Google Cloud console and the VM's \u003ccode\u003e/var/log/syslog.log\u003c/code\u003e file, and changes made while debugging are temporary.\u003c/p\u003e\n"],["\u003cp\u003eDebug mode can be toggled on and off using the \u003ccode\u003egcloud\u003c/code\u003e command-line tool, with specific permissions required, and will restart the VM and start a new instance of your app.\u003c/p\u003e\n"],["\u003cp\u003eYou can connect to an instance in debug mode via the Google Cloud console by clicking "SSH" or through \u003ccode\u003egcloud\u003c/code\u003e, allowing access to the host and containers.\u003c/p\u003e\n"],["\u003cp\u003eBesides your application container, instances may contain sidecar containers for Cloud SQL connections, logging, request proxying, telemetry, and system monitoring, which are subject to change.\u003c/p\u003e\n"]]],[],null,["# Debugging an instance\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| **Note:** This guide is applicable to all runtimes in the flexible environment except for .NET.\n\nYou can enable debug mode for a VM. In debug mode, principals who have the\nOwner, Editor, and App Engine Admin roles on the project have root access to the\nVM. While debug mode is turned on, the automatic rollout of operating system\nupdates and security patches is disabled. However, the VM is still part of the\nload balancer pool, and continues to receive external requests.\n\nWhenever you enable or disable debugging, a \"VM instance debugging enable/disable\"\nevent appears in the Google Cloud console and the event will be logged in the VM's\n`/var/log/syslog.log` file.\n| **Important:** Any changes you make to the VM while in debug mode are temporary; you will lose your changes when you disable debug mode. VMs that are being debugged restart periodically, which can make it difficult to debug long running tasks.\n\nEnabling and disabling debug mode\n---------------------------------\n\nYou can use `gcloud` to enable and disable debug mode for an\ninstance. In order to debug an instance, your role must contain the\n`appengine.instances.enableDebug` permission.\n| **Note:** To enable debug mode in the Google Cloud console, you must [connect using SSH](#connecting_to_the_instance).\n\nTo enable and disable debug mode in `gcloud`:\n\n1. Use the [gcloud\n app instances enable-debug](/sdk/gcloud/reference/app/instances/enable-debug) command to debug the VMs for a particular instance and version, as follows: \n\n ```\n gcloud app --project PROJECT-ID instances enable-debug\n ```\n Replace \u003cvar translate=\"no\"\u003ePROJECT-ID\u003c/var\u003e with your own project ID, and follow the prompts to specify the instance version to debug.\n2. When finished debugging, disable debug mode as follows: \n\n ```\n gcloud app --project PROJECT-ID instances disable-debug\n ```\n Follow the prompts to specify the instance version\n\nWhen you disable debug mode, the VM is stopped and a new instance of\nyour app is started, running on a clean, new VM.\n\nConnecting to the instance\n--------------------------\n\n### Console\n\n| **Note:** If [OS Login is enabled](/compute/docs/troubleshooting/troubleshoot-os-login#checking_if_os_login_is_enabled) in project metadata, use the gcloud CLI to connect to the instance.\n\nTo connect to an instance in the console:\n\n1. Visit the Google Cloud console instances page for your project:\n\n [Go to the instances page](https://console.cloud.google.com/appengine/instances)\n2. Click **SSH** in the far right of the row containing the instance you\n want to access:\n\n \u003cbr /\u003e\n\n This puts the instance into debug mode, and opens an SSH session for the\n instance in a terminal window.\n\n You can also select different options to start an SSH session from the\n drop-down list.\n3. At this point you are in the instance host, which has several\n [containers](https://kubernetes.io/docs/concepts/overview/) running in\n it. See [Understanding common containers](#understanding_common_containers)\n next for more information about these.\n\n4. In the terminal window, list the containers running in the instance:\n\n ```\n sudo docker ps\n ```\n\n \u003cbr /\u003e\n\n5. The output of the `sudo docker ps` command lists each\n container by row; locate the row that contains your project ID: this is\n the container running your code. Note the NAME of this container.\n\n6. Optionally, list logging information for your application by invoking:\n\n ```\n sudo docker logs CONTAINER-NAME\n ```\n\n \u003cbr /\u003e\n\n7. Start a shell in the container that is running your code:\n\n ```\n sudo docker exec -it CONTAINER-NAME /bin/bash\n ```\n\n \u003cbr /\u003e\n\n8. When finished debugging, enter `exit` to exit the container,\n then `exit` again to exit the SSH session.\n\n9. Disable debugging for your instance to allow it to resume normal\n operation.\n\n### gcloud\n\nTo connect to an instance using gcloud:\n\n\u003cbr /\u003e\n\n1. With the instance [enabled for debugging](#enabling_and_disabling_debug_mode),\n invoke the command:\n\n ```\n gcloud beta app instances --project PROJECT-ID ssh INSTANCE-NAME --service SERVICE --version VERSION\n ```\n\n \u003cbr /\u003e\n\n2. At this point you are in the instance host, which has several\n [containers](http://kubernetes.io/docs/whatisk8s/) running.\n See [Understanding common containers](#understanding_common_containers) next for more information about these.\n\n3. In the terminal window, list the containers running in the instance:\n\n ```\n sudo docker ps\n ```\n\n \u003cbr /\u003e\n\n4. The output of the `sudo docker ps` command lists each\n container by row; locate the row that contains your project ID: this is\n the container running your code. Note the NAME of this container.\n\n5. Optionally, list logging information for your application by invoking:\n\n ```\n sudo docker logs CONTAINER-NAME\n ```\n\n \u003cbr /\u003e\n\n6. Start a shell in the container that is running your code:\n\n ```\n docker exec -it CONTAINER-NAME /bin/bash\n ```\n\n \u003cbr /\u003e\n\n7. When finished debugging, enter `exit` to exit the container,\n then `exit` again to exit the SSH session.\n\n8. Disable debugging for your instance to allow it to resume normal\n operation.\n\nUnderstanding common containers\n-------------------------------\n\nIn addition to the container running your application code, your instance may\nalso have the following containers:\n\nNote that these sidecar containers are subject to change without notice."]]