This topic describes how to enable the coredump feature. After you enable the coredump feature, you can view and analyze a core file to identify the cause of the issue when a container is unexpectedly terminated.
Background information
In a Linux system, if a program unexpectedly terminates or exits, the operating system records the state of the random access memory (RAM) that is allocated to the program and saves the state to a file. This process is called a core dump. You can view and analyze the core file that is generated from the core dump to identify the cause of the issue.
The following figure shows the signals that indicate core dumps in Linux. The values of the signals in the Action column are Core.
For more information, see Core dump file.
Description
By default, coredump is disabled in elastic container instances to prevent service unavailability that is caused by excessive disk usage. You can use one of the following methods to use coredump:
Method 1: Execute a coredump O&M task
After you enable coredump, the system generates an O&M task. If a container unexpectedly terminates or exits, the system triggers coredump to generate a core file and save the core file to an Object Storage Service (OSS) bucket.
Method 2: Specify a path to store core files
Elastic Container Instance allows you to use an external storage device to store core files. After you specify the storage device, coredump is automatically enabled for Elastic Container Instance. If a container unexpectedly terminates or exits, the system triggers coredump to generate a core file and save the core file to the specified external storage device.
Method 1 is easy to use, but has limits on the regions that you specify and the validity periods of the O&M tasks. Method 1 is suitable for temporary program debugging and diagnostics.
Generated O&M tasks can be executed only once. After an O&M task is executed and a core file is generated, coredump is disabled. The validity period of an O&M task is 12 hours.
You cannot manually execute coredump O&M tasks for the following regions: China (Ulanqab), China (Heyuan), China (Guangzhou), China (Nanjing), Philippines (Manila), South Korea (Seoul), and Thailand (Bangkok).
You cannot manually execute coredump O&M tasks for job-optimized elastic container instances.
Method 2 requires an external storage device. You can use this method to acquire core files even if the program is unstable. However, if the program repeatedly restarts, a large number of core files may be generated.
Method 1: Execute a coredump O&M task
Use the Elastic Container Instance console
Log on to the Elastic Container Instance console.
Enable coredump for an instance.
In the left-side navigation pane, click Container Group. On the Container Group page, click the ID of the instance for which you want to enable coredump to go to the instance details page.
On the O&M tab, click the Core dump tab, and then click Enable.
After you enable coredump, the system generates an O&M task. Before coredump is triggered, the task is in the Pending state.
Trigger coredump.
Connect to the elastic container instance. After you run the following
sleep 100
command in the container, press theCtrl
key and the\
key at the same time to trigger coredump. A core file is automatically generated and saved to an OSS bucket.Download the core file.
After coredump is triggered and the system generates a core file, the state of the O&M task changes to Successful. Click Download in the Result column to download the core file to your on-premises machine.
NoteIf the system does not respond, check the website permission settings of your browser.
Call an API operation
Enable coredump for an instance.
To create an O&M task by calling the CreateInstanceOpsTask API operation, you must specify the instance for which you want to enable coredump and set OpsType to
coredump
and OpsValue toenable
. For more information, see CreateInstanceOpsTask.NoteMake sure that CorePattern is not set for the instance that you want to specify when you create the instance.
Trigger coredump.
Connect to the elastic container instance. After you run the following
sleep 100
command in the container, press theCtrl
key and the\
key at the same time to trigger coredump. A core file is automatically generated and saved to an OSS bucket.Download the core file.
Call the DescribeInstanceOpsRecords API operation to query the result of the O&M task that is executed. The ResultContent response parameter indicates the OSS bucket path of the core file. You can download the core file from the path.
Method 2: Specify a path to store core files
Core files are used to analyze issues offline. In most cases, core files are stored on external storage devices instead of local storage of containers. This prevents loss of core files if containers terminate. Elastic Container Instance allows you to specify a path to store core files. After you specify a path, coredump is automatically enabled.
When you call the CreateContainerGroup API operation to create an elastic container instance, you can use the CorePattern parameter to specify the path to store core files. The following table describes the parameters that are related to the path to store core files. For more information, see CreateContainerGroup.
Parameter | Type | Example | Description |
CorePattern | String | /data/dump-a/core | The path to store core files. Important The path cannot start with a vertical bar ( |
Volume.N.Name | String | volume1 | The name of volume N. |
Volume.N.Type | String | NFSVolume | The type of volume N. Examples of the valid values: EmptyDirVolume, NFSVolume, ConfigFileVolume, and FlexVolume. NFSVolume is used in this topic. |
Volume.N.NFSVolume.Path | String | /dump | The path to the Network File System (NFS) volume. |
Volume.N.NFSVolume.Server | String | 143b24****-gfn3.cn-beijing.nas.aliyuncs.com | The endpoint of the NFS server. |
Container.N.VolumeMount.N.Name | String | volume1 | The name of volume N. The value of this parameter is the same as the value of the Volume.N.Name parameter. |
Container.N.VolumeMount.N.MountPath | String | /data/dump-a/ | The directory in which volume N is mounted. |
In the preceding table, NFSVolume is used as the volume type. You must configure these parameters based on your actual volume type.
The following part describes how to enable coredump if you use a NAS file system as an external storage.
Create Elastic Container Instance A, mount a NAS file system to Elastic Container Instance A, and specify a path to store core files.
When you call the CreateContainerGroup API operation to create Elastic Container Instance A, configure the following parameters to mount the
/dump/
directory of the NAS file system to the/data/dump-a/
directory of the container and set the/data/dump-a/core
path to store core files.'Volume.1.Name': 'volume1', 'Volume.1.Type': 'NFSVolume', 'Volume.1.NFSVolume.Path': '/dump/', 'Volume.1.NFSVolume.Server': '143b24****-gfn3.cn-beijing.nas.aliyuncs.com', 'Container.1.VolumeMount.1.Name': 'volume1', 'Container.1.VolumeMount.1.MountPath': '/data/dump-a/', 'CorePattern':'/data/dump-a/core',
Trigger coredump in a directory of the container on Elastic Container Instance A.
For example, after you run the
sleep 100
command in the container, you can press theCtrl
key and the\
key at the same time to trigger coredump. The core file is saved to the/data/dump-a/
path of the container.Release Elastic Container Instance A.
Mount the same NAS file system to Elastic Container Instance B.
When you call the CreateContainerGroup API operation to create Elastic Container Instance B, configure the following parameters to mount the
/dump/
directory of the NAS file system to the/data/dump-b/
directory of the container.'Volume.1.Name': 'volume1', 'Volume.1.Type': 'NFSVolume', 'Volume.1.NFSVolume.Path': '/dump/', 'Volume.1.NFSVolume.Server': '143b24****-gfn3.cn-beijing.nas.aliyuncs.com', 'Container.1.VolumeMount.1.Name': 'dvolume1', 'Container.1.VolumeMount.1.MountPath': '/data/dump-b/',
View the core file in the container of Elastic Container Instance B.
The following figure shows that the core file is stored in the
/data/dump-b/
path of the container. The core file is not lost after Elastic Container Instance A is released because the core file is stored in an external storage device.
FAQ
The system does not respond after coredump is triggered in the Elastic Container Instance console and I click Download in the Result column of the O&M task. What do I do?
If the system does not respond, check the website permission settings of your browser. For example, if you use Google Chrome, you can use the following method to allow the download:
In the Elastic Container Instance console, click the
icon in the address bar of your browser, and then select Site settings.
Change the settings of the configuration item Insecure content to Allow.