All Products
Search
Document Center

Python SDK examples

Last Updated: Aug 15, 2019

Prerequisites

Install Elastic Container Instance (ECI) SDK

ECI Python SDK address on PyPI:

https://pypi.org/project/aliyun-python-sdk-eci/

Run the following command to install it:

pip install aliyun-python-sdk-eci==1.0.3

If a timeout prompt appears, add the timeout option:

pip --default-timeout=100 install aliyun-python-sdk-eci==1.0.3

To upgrade the SDK to the latest version, run the following command:

pip install --upgrade aliyun-python-sdk-eci

Create a client

Request parameters

Parameter Type Required Description
region String Yes The ID of the region in which the container group resides.
accessKey String Yes The AccessKey ID of the user.
secretKey String Yes The AccessKey Secret of the user.
Response parameters
Parameter Type Description
eciClient aliyunsdkcore.client.AcsClient The client that is used to call the ECI API.
Sample code
  1. from aliyunsdkcore.client import AcsClient
  2. eciClient = AcsClient(accessKey, secretKey, region)

Create a container group

Request parameters of CreateContainerGroupRequest

Parameter Type Required Description
SecurityGroupId String Yes The ID of the security group.
VSwitchId String Yes The ID of the VSwitch.
ContainerGroupName String Yes The name of the container group. The name does not have to be unique. The name must be 2 to 128 characters in length. It must contain lowercase letters, numbers, and hyphens (-). It cannot start or end with a hyphen (-).
InitContainers Container[] No The initial list of containers.
Containers Container[] Yes The list of containers.
ZoneId String No The ID of the zone in which the container group resides. If you leave this parameter blank, the system assigns a zone for this container group. Default value: blank.
RestartPolicy String No The policy for restarting the container group. Default value: Always.
Tags Tag[] No The tag of the container.
ImageRegistryCredentials ImageRegistryCredential[] No The information for logging on to the image repository.
Volumes Volume[] No The list of volumes.
EipInstanceId String No The ID of the EIP instance.

Response parameters of CreateContainerGroupResponse

Parameter Type Description
ContainerGroupId String The ID of the container group.
RequestId String The ID of the request.
Sample code
  1. from aliyunsdkeci.request.v20180808.CreateContainerGroupRequest import CreateContainerGroupRequest
  2. request = CreateContainerGroupRequest()
  3. request.set_SecurityGroupId(secureGroup-xxx)
  4. request.set_VSwitchId(vSwitch-xxx)
  5. request.set_ContainerGroupName(name-xxx)
  6. request.set_EipInstanceId(eip-xxx)
  7. request.set_RestartPolicy('Always')
  8. # Volumes. The first is EmptyDirVolume, which is used for data sharing among containers. The second is NFSVolume, which is used to load Alibaba Cloud NAS.
  9. volume1 = {
  10. 'Name': 'default-volume1-empty',
  11. 'Type': 'EmptyDirVolume',
  12. }
  13. # The NFS volume requires you to configure the NFS server.
  14. volume2 = {
  15. 'Name': 'default-volume2-nfs',
  16. 'Type': 'NFSVolume',
  17. 'NFSVolume.Path': '/',
  18. 'NFSVolume.Server': 'yourserver.cn-hangzhou.nas.aliyuncs.com',
  19. 'NFSVolume.ReadOnly': False,
  20. }
  21. # Content must be Base64-coded.
  22. configFileToPath1 = {
  23. 'Path': 'nginx-proxy.conf',
  24. 'Content': 'aGVsbG8gd29ybGQ=',
  25. }
  26. configFileToPath2 = {
  27. 'Path': 'access.lua',
  28. 'Content': 'aGVsbG8gd29ybGQ=',
  29. }
  30. volume3 = {
  31. 'Name': 'default-volume3-config',
  32. 'Type': 'ConfigFileVolume',
  33. 'ConfigFileVolume.ConfigFileToPaths': [configFileToPath1, configFileToPath2],
  34. }
  35. # Install volumes to containerGroup
  36. request.set_Volumes([volume1, volume2, volume3])
  37. #tags
  38. tag1 = {
  39. 'Key': 'test',
  40. 'Value': 'sdk-python',
  41. }
  42. tag2 = {
  43. 'Key': 'app',
  44. 'Value': 'nginx',
  45. }
  46. # Add tags for containerGroup
  47. request.set_Tags([tag1, tag2])
  48. #dns options
  49. option1 = {
  50. 'Name': 'name1',
  51. 'Value': 'value1',
  52. }
  53. option2 = {
  54. 'Name': 'name2',
  55. 'Value': 'value2',
  56. }
  57. #DNS config
  58. request.set_DnsConfigOptions([option1, option2])
  59. #request.set_DnsConfigNameServers(['8.8.8.8', '127.0.0.1'])
  60. #request.set_DnsConfigSearchs(['ns.svc.cluster.local'])
  61. # VolumeMounts, which mounts the volumes that were installed by containerGroup to the container directory
  62. volume_mount1 = {
  63. 'Name': 'default-volume1-empty',
  64. 'MountPath': '/usr/share',
  65. 'ReadOnly': False,
  66. }
  67. volume_mount2 = {
  68. 'Name': 'default-volume2-nfs',
  69. 'MountPath': '/pod-data',
  70. 'ReadOnly': False,
  71. }
  72. volume_mount3 = {
  73. 'Name': 'default-volume1-empty',
  74. 'MountPath': '/usr/share/nginx/html',
  75. 'ReadOnly': False,
  76. }
  77. volume_mount4 = {
  78. 'Name': 'default-volume3-config',
  79. 'MountPath': '/etc/liumi/',
  80. 'ReadOnly': False,
  81. }
  82. #environment variable
  83. env ={
  84. 'Key': 'MESSAGE',
  85. 'Value': 'hello world',
  86. }
  87. #container ports
  88. port = {
  89. 'Protocol':'TCP',
  90. 'Port': 8080,
  91. }
  92. #initContainers
  93. initContainer = {
  94. 'Image': 'registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0',
  95. 'Name': 'init-liu',
  96. # Configure the number of vCPUs and memory size according to documentation.
  97. 'Cpu': 1.0,
  98. 'Memory': 2.0,
  99. 'VolumeMounts': [volume_mount1, volume_mount2],
  100. 'Commands': ['/bin/sh'],
  101. 'Args': ['-c', 'cp -r /pod-data/ /usr/share/'],
  102. 'EnvironmentVars': [env],
  103. 'Ports': [port],
  104. }
  105. # containers
  106. container1 = {
  107. 'Image': 'registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0',
  108. 'Name': 'busy-liu',
  109. 'Cpu': 0.5,
  110. 'Memory': 1.0,
  111. 'ImagePullPolicy': 'Always',
  112. 'Commands':['/bin/sh'],
  113. 'Args': ['-c', 'cp -r /pod-data/ /usr/share/'],
  114. 'VolumeMounts': [volume_mount1, volume_mount2],
  115. }
  116. container2 = {
  117. 'Image': 'registry-vpc.cn-hangzhou.aliyuncs.com/jovi/nginx:alpine',
  118. 'Name': 'nginx-liu',
  119. 'Cpu': 0.5,
  120. 'Memory': 1.0,
  121. 'ImagePullPolicy': 'Always',
  122. 'VolumeMounts': [volume_mount3, volume_mount4],
  123. 'EnvironmentVars': [env],
  124. 'Ports': [port],
  125. ##'ReadinessProbe.HttpGet.Path':'/heath',
  126. ##'ReadinessProbe.HttpGet.Port': 80,
  127. #'ReadinessProbe.Exec.Commands': ['/bin/sh', '-c', 'cat /etc/nginx/nginx.conf'],
  128. ##'ReadinessProbe.TcpSocket.Port': 80,
  129. #'ReadinessProbe.InitialDelaySeconds': 10,
  130. #'ReadinessProbe.PeriodSeconds': 10,
  131. #'ReadinessProbe.FailureThreshold': 3,
  132. #'ReadinessProbe.SuccessThreshold': 3,
  133. #'ReadinessProbe.TimeoutSeconds': 5,
  134. #'LivenessProbe.Exec.Commands': ['/bin/sh', '-c', 'cat /etc/nginx/nginx.conf'],
  135. ##'LivenessProbe.TcpSocket.Port': 80,
  136. #'LivenessProbe.InitialDelaySeconds': 10,
  137. #'LivenessProbe.PeriodSeconds': 10,
  138. #'LivenessProbe.FailureThreshold': 3,
  139. #'LivenessProbe.SuccessThreshold': 1,
  140. #'LivenessProbe.TimeoutSeconds': 5,
  141. #'SecurityContext.Capability.Adds': ['NET_ADMIN'],
  142. #'SecurityContext.ReadOnlyRootFilesystem': True,
  143. #'SecurityContext.RunAsUser': 1337,
  144. }
  145. request.set_InitContainers([initContainer])
  146. request.set_Containers([container1,container2])
  147. response = eciClient.do_action_with_exception(request)
  148. print response

Output

  1. {"ContainerGroupId":"eci-bp1jfs45an09sg8k9cnf","RequestId":"C8BE6D53-2297-4EB8-8C7F-9B71A07B4545"}

Delete a container group

Request parameters of DeleteContainerGroupRequest

Parameter Type Required Description
ContainerGroupId String Yes The ID of the container group.

Response parameters of DeleteContainerGroupResponse

Parameter Type Description
RequestId String The ID of the request.
Sample code
  1. from aliyunsdkeci.request.v20180808.DeleteContainerGroupRequest import DeleteContainerGroupRequest
  2. request = DeleteContainerGroupRequest()
  3. request.set_ContainerGroupId('eci-xxx')
  4. response = eciClient.do_action_with_exception(request)
  5. print response

Output

  1. {"RequestId":"8050300F-3D96-46FC-8AC1-6485080B7992"}

Query container groups

Request parameters of DescribeContainerGroupsRequest

Parameter Type Required Description
ZoneId String No The ID of the zone in which the container group resides. If you leave this parameter blank, the system assigns a zone for this container group. Default value: blank.
VSwitchId String No The ID of the VSwitch.
NextToken String No Returns more results. You do not need to specify the parameter value in the first call. If a NextToken is returned by a previous call, there are more results available.
Limit Integer No The limit on the returned resources of the current request. Default value: 20. Maximum: 20. The returned results are no more than the specified number.
Tags Tag[] No The tag of the container. You can query a maximum of 10 tags.
ContainerGroupId String[] No The ID of the container group. You can query the IDs of up to 20 container groups.
ContainerGroupName String No The name of the container group.

Response parameters of DescribeContainerGroupsResponse

Parameter Type Description
RequestId String The ID of the request.
NextToken String Returns more results. The token of the subsequent query is obtained from the response.
TotalCount Integer The number of container groups.
ContainerGroups ContainerGroup[] The detailed information about the container group.
Sample code
  1. from aliyunsdkeci.request.v20180808.DescribeContainerGroupsRequest import DescribeContainerGroupsRequest
  2. request = DescribeContainerGroupsRequest()
  3. # Note: The containerGroupIds array must be encoded in JSON format.
  4. request.set_ContainerGroupIds(json.dumps(ContainerGroupIds))
  5. # Queries with tag filtering are supported.
  6. tag = {
  7. 'Key': 'test',
  8. 'Value': 'sdk-python',
  9. }
  10. request.set_Tags([tag])
  11. response = eciClient.do_action_with_exception(request)
  12. print response

Output

  1. {
  2. "ContainerGroups": [
  3. {
  4. "ContainerGroupId": "eci-bp1ddjhfcjtrwvpcpxem",
  5. "ContainerGroupName": "test-python-sdk",
  6. "Containers": [
  7. {
  8. "Args": [
  9. "-c",
  10. "cp -r /pod-data/ /usr/share/ && sleep 3600"
  11. ],
  12. "Commands": [
  13. "/bin/sh"
  14. ],
  15. "Cpu": 0.5,
  16. "CurrentState": {
  17. "FinishTime": "",
  18. "StartTime": "2019-01-03T09:28:00Z",
  19. "State": "Running"
  20. },
  21. "EnvironmentVars": [],
  22. "Image": "registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0",
  23. "ImagePullPolicy": "Always",
  24. "LivenessProbe": {
  25. "HttpGet": {},
  26. "TcpSocket": {}
  27. },
  28. "Memory": 1.0,
  29. "Name": "busy-liu",
  30. "Ports": [],
  31. "PreviousState": {
  32. "FinishTime": "",
  33. "StartTime": "",
  34. "State": ""
  35. },
  36. "ReadinessProbe": {
  37. "HttpGet": {},
  38. "TcpSocket": {}
  39. },
  40. "RestartCount": 0,
  41. "SecurityContext": {
  42. "Capability": {}
  43. },
  44. "VolumeMounts": [
  45. {
  46. "MountPath": "/usr/share",
  47. "Name": "default-volume1-empty",
  48. "ReadOnly": false
  49. },
  50. {
  51. "MountPath": "/pod-data",
  52. "Name": "default-volume2-nfs",
  53. "ReadOnly": false
  54. }
  55. ],
  56. "WorkingDir": ""
  57. },
  58. {
  59. "Cpu": 0.5,
  60. "CurrentState": {
  61. "FinishTime": "",
  62. "StartTime": "2019-01-03T09:28:02Z",
  63. "State": "Running"
  64. },
  65. "EnvironmentVars": [
  66. {
  67. "Key": "MESSAGE",
  68. "Value": "hello world"
  69. }
  70. ],
  71. "Image": "registry-vpc.cn-hangzhou.aliyuncs.com/jovi/nginx:alpine",
  72. "ImagePullPolicy": "Always",
  73. "LivenessProbe": {
  74. "HttpGet": {},
  75. "TcpSocket": {}
  76. },
  77. "Memory": 1.0,
  78. "Name": "nginx-liu",
  79. "Ports": [
  80. {
  81. "Port": 8080,
  82. "Protocol": "TCP"
  83. }
  84. ],
  85. "PreviousState": {
  86. "FinishTime": "",
  87. "StartTime": "",
  88. "State": ""
  89. },
  90. "ReadinessProbe": {
  91. "HttpGet": {},
  92. "TcpSocket": {}
  93. },
  94. "RestartCount": 0,
  95. "SecurityContext": {
  96. "Capability": {}
  97. },
  98. "VolumeMounts": [
  99. {
  100. "MountPath": "/usr/share/nginx/html",
  101. "Name": "default-volume1-empty",
  102. "ReadOnly": false
  103. },
  104. {
  105. "MountPath": "/etc/liumi/",
  106. "Name": "default-volume3-config",
  107. "ReadOnly": false
  108. }
  109. ],
  110. "WorkingDir": ""
  111. }
  112. ],
  113. "Cpu": 1.0,
  114. "CreationTime": "2019-01-03T09:27:49Z",
  115. "DnsConfig": {
  116. "Options": [
  117. {
  118. "Name": "name1",
  119. "Value": "value1"
  120. },
  121. {
  122. "Name": "name2",
  123. "Value": "value2"
  124. }
  125. ]
  126. },
  127. "EniInstanceId": "eni-bp1hyp5oips8yau23dyk",
  128. "Events": [
  129. {
  130. "Count": 1,
  131. "FirstTimestamp": "2019-01-03T09:27:56Z",
  132. "LastTimestamp": "2019-01-03T09:27:56Z",
  133. "Message": "MountVolume.SetUp succeeded for volume \"default-volume3-config\" ",
  134. "Name": "test-python-sdk.15764c89a2da411f",
  135. "Reason": "SuccessfulMountVolume",
  136. "Type": "Normal"
  137. },
  138. {
  139. "Count": 1,
  140. "FirstTimestamp": "2019-01-03T09:27:56Z",
  141. "LastTimestamp": "2019-01-03T09:27:56Z",
  142. "Message": "MountVolume.SetUp succeeded for volume \"default-volume1-empty\" ",
  143. "Name": "test-python-sdk.15764c89a31002e6",
  144. "Reason": "SuccessfulMountVolume",
  145. "Type": "Normal"
  146. },
  147. {
  148. "Count": 1,
  149. "FirstTimestamp": "2019-01-03T09:27:57Z",
  150. "LastTimestamp": "2019-01-03T09:27:57Z",
  151. "Message": "MountVolume.SetUp succeeded for volume \"default-volume2-nfs\" ",
  152. "Name": "test-python-sdk.15764c89e21f9ab6",
  153. "Reason": "SuccessfulMountVolume",
  154. "Type": "Normal"
  155. },
  156. {
  157. "Count": 1,
  158. "FirstTimestamp": "2019-01-03T09:27:57Z",
  159. "LastTimestamp": "2019-01-03T09:27:57Z",
  160. "Message": "pulling image \"registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0\"",
  161. "Name": "test-python-sdk.15764c89e7f364de",
  162. "Reason": "Pulling",
  163. "Type": "Normal"
  164. },
  165. {
  166. "Count": 1,
  167. "FirstTimestamp": "2019-01-03T09:27:58Z",
  168. "LastTimestamp": "2019-01-03T09:27:58Z",
  169. "Message": "Successfully pulled image \"registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0\"",
  170. "Name": "test-python-sdk.15764c8a30f0c918",
  171. "Reason": "Pulled",
  172. "Type": "Normal"
  173. },
  174. {
  175. "Count": 1,
  176. "FirstTimestamp": "2019-01-03T09:27:58Z",
  177. "LastTimestamp": "2019-01-03T09:27:58Z",
  178. "Message": "Created container",
  179. "Name": "test-python-sdk.15764c8a340debbf",
  180. "Reason": "Created",
  181. "Type": "Normal"
  182. },
  183. {
  184. "Count": 1,
  185. "FirstTimestamp": "2019-01-03T09:27:58Z",
  186. "LastTimestamp": "2019-01-03T09:27:58Z",
  187. "Message": "Started container",
  188. "Name": "test-python-sdk.15764c8a37a0c791",
  189. "Reason": "Started",
  190. "Type": "Normal"
  191. },
  192. {
  193. "Count": 1,
  194. "FirstTimestamp": "2019-01-03T09:27:59Z",
  195. "LastTimestamp": "2019-01-03T09:27:59Z",
  196. "Message": "pulling image \"registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0\"",
  197. "Name": "test-python-sdk.15764c8a77ad5645",
  198. "Reason": "Pulling",
  199. "Type": "Normal"
  200. },
  201. {
  202. "Count": 1,
  203. "FirstTimestamp": "2019-01-03T09:28:00Z",
  204. "LastTimestamp": "2019-01-03T09:28:00Z",
  205. "Message": "Successfully pulled image \"registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0\"",
  206. "Name": "test-python-sdk.15764c8aa1a02fb9",
  207. "Reason": "Pulled",
  208. "Type": "Normal"
  209. },
  210. {
  211. "Count": 1,
  212. "FirstTimestamp": "2019-01-03T09:28:00Z",
  213. "LastTimestamp": "2019-01-03T09:28:00Z",
  214. "Message": "Created container",
  215. "Name": "test-python-sdk.15764c8aa3d4183c",
  216. "Reason": "Created",
  217. "Type": "Normal"
  218. },
  219. {
  220. "Count": 1,
  221. "FirstTimestamp": "2019-01-03T09:28:00Z",
  222. "LastTimestamp": "2019-01-03T09:28:00Z",
  223. "Message": "Started container",
  224. "Name": "test-python-sdk.15764c8aa710b3f9",
  225. "Reason": "Started",
  226. "Type": "Normal"
  227. },
  228. {
  229. "Count": 1,
  230. "FirstTimestamp": "2019-01-03T09:28:00Z",
  231. "LastTimestamp": "2019-01-03T09:28:00Z",
  232. "Message": "pulling image \"registry-vpc.cn-hangzhou.aliyuncs.com/jovi/nginx:alpine\"",
  233. "Name": "test-python-sdk.15764c8aa71a2a14",
  234. "Reason": "Pulling",
  235. "Type": "Normal"
  236. },
  237. {
  238. "Count": 1,
  239. "FirstTimestamp": "2019-01-03T09:28:02Z",
  240. "LastTimestamp": "2019-01-03T09:28:02Z",
  241. "Message": "Successfully pulled image \"registry-vpc.cn-hangzhou.aliyuncs.com/jovi/nginx:alpine\"",
  242. "Name": "test-python-sdk.15764c8b15c28c74",
  243. "Reason": "Pulled",
  244. "Type": "Normal"
  245. },
  246. {
  247. "Count": 1,
  248. "FirstTimestamp": "2019-01-03T09:28:02Z",
  249. "LastTimestamp": "2019-01-03T09:28:02Z",
  250. "Message": "Created container",
  251. "Name": "test-python-sdk.15764c8b185298b7",
  252. "Reason": "Created",
  253. "Type": "Normal"
  254. },
  255. {
  256. "Count": 1,
  257. "FirstTimestamp": "2019-01-03T09:28:02Z",
  258. "LastTimestamp": "2019-01-03T09:28:02Z",
  259. "Message": "Started container",
  260. "Name": "test-python-sdk.15764c8b1b9aee37",
  261. "Reason": "Started",
  262. "Type": "Normal"
  263. },
  264. {
  265. "Count": 1,
  266. "FirstTimestamp": "2019-01-03T09:33:37Z",
  267. "LastTimestamp": "2019-01-03T09:33:37Z",
  268. "Message": "Container image \"registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0\" already present on machine",
  269. "Name": "test-python-sdk.15764cd91ea636aa",
  270. "Reason": "Pulled",
  271. "Type": "Normal"
  272. },
  273. {
  274. "Count": 1,
  275. "FirstTimestamp": "2019-01-03T09:33:37Z",
  276. "LastTimestamp": "2019-01-03T09:33:37Z",
  277. "Message": "Created container",
  278. "Name": "test-python-sdk.15764cd92092af49",
  279. "Reason": "Created",
  280. "Type": "Normal"
  281. },
  282. {
  283. "Count": 1,
  284. "FirstTimestamp": "2019-01-03T09:33:37Z",
  285. "LastTimestamp": "2019-01-03T09:33:37Z",
  286. "Message": "Started container",
  287. "Name": "test-python-sdk.15764cd923f53212",
  288. "Reason": "Started",
  289. "Type": "Normal"
  290. },
  291. {
  292. "Count": 1,
  293. "FirstTimestamp": "2019-01-03T09:40:03Z",
  294. "LastTimestamp": "2019-01-03T09:40:03Z",
  295. "Message": "Container image \"registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0\" already present on machine",
  296. "Name": "test-python-sdk.15764d32fdfe8609",
  297. "Reason": "Pulled",
  298. "Type": "Normal"
  299. },
  300. {
  301. "Count": 1,
  302. "FirstTimestamp": "2019-01-03T09:40:03Z",
  303. "LastTimestamp": "2019-01-03T09:40:03Z",
  304. "Message": "Created container",
  305. "Name": "test-python-sdk.15764d33007fa5e5",
  306. "Reason": "Created",
  307. "Type": "Normal"
  308. },
  309. {
  310. "Count": 1,
  311. "FirstTimestamp": "2019-01-03T09:40:03Z",
  312. "LastTimestamp": "2019-01-03T09:40:03Z",
  313. "Message": "Started container",
  314. "Name": "test-python-sdk.15764d33042e3e93",
  315. "Reason": "Started",
  316. "Type": "Normal"
  317. }
  318. ],
  319. "InitContainers": [
  320. {
  321. "Args": [
  322. "-c",
  323. "cp -r /pod-data/ /usr/share/"
  324. ],
  325. "Command": [
  326. "/bin/sh"
  327. ],
  328. "Cpu": 1.0,
  329. "CurrentState": {
  330. "ExitCode": 0,
  331. "FinishTime": "2019-01-03T09:40:03Z",
  332. "Reason": "Completed",
  333. "StartTime": "2019-01-03T09:40:03Z",
  334. "State": "Terminated"
  335. },
  336. "EnvironmentVars": [
  337. {
  338. "Key": "MESSAGE",
  339. "Value": "hello world"
  340. }
  341. ],
  342. "Image": "registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0",
  343. "ImagePullPolicy": "IfNotPresent",
  344. "Memory": 2.0,
  345. "Name": "init-liu",
  346. "Ports": [
  347. {
  348. "Port": 8080,
  349. "Protocol": "TCP"
  350. }
  351. ],
  352. "PreviousState": {
  353. "FinishTime": "",
  354. "StartTime": "",
  355. "State": ""
  356. },
  357. "RestartCount": 0,
  358. "SecurityContext": {
  359. "Capability": {
  360. "Adds": [
  361. "NET_ADMIN"
  362. ]
  363. },
  364. "ReadOnlyRootFilesystem": true,
  365. "RunAsUser": 1337
  366. },
  367. "VolumeMounts": [
  368. {
  369. "MountPath": "/usr/share",
  370. "Name": "default-volume1-empty",
  371. "ReadOnly": false
  372. },
  373. {
  374. "MountPath": "/pod-data",
  375. "Name": "default-volume2-nfs",
  376. "ReadOnly": false
  377. }
  378. ],
  379. "WorkingDir": ""
  380. }
  381. ],
  382. "InternetIp": "",
  383. "IntranetIp": "192.168.1.218",
  384. "Memory": 2.0,
  385. "RegionId": "cn-hangzhou",
  386. "RestartPolicy": "Always",
  387. "SecurityGroupId": "sg-bp11zjwu3eumpw32memr",
  388. "Status": "Running",
  389. "SucceededTime": "",
  390. "Tags": [
  391. {
  392. "Key": "test",
  393. "Value": "sdk-python"
  394. },
  395. {
  396. "Key": "app",
  397. "Value": "nginx"
  398. }
  399. ],
  400. "VSwitchId": "vsw-bp1a6dake404nwul5yoec",
  401. "Volumes": [
  402. {
  403. "Name": "default-volume1-empty",
  404. "Type": "EmptyDirVolume"
  405. },
  406. {
  407. "NFSVolumePath": "/",
  408. "NFSVolumeReadOnly": false,
  409. "NFSVolumeServer": "0551049961-eqr13.cn-hangzhou.nas.aliyuncs.com",
  410. "Name": "default-volume2-nfs",
  411. "Type": "NFSVolume"
  412. },
  413. {
  414. "ConfigFileVolumeConfigFileToPaths": [
  415. {
  416. "Path": "nginx-proxy.conf"
  417. },
  418. {
  419. "Path": "access.lua"
  420. }
  421. ],
  422. "Name": "default-volume3-config",
  423. "Type": "ConfigFileVolume"
  424. }
  425. ],
  426. "ZoneId": "cn-hangzhou-g"
  427. }
  428. ],
  429. "NextToken": "",
  430. "RequestId": "3213275D-E2F9-4903-BE52-D0625A3C9F03",
  431. "TotalCount": 1
  432. }

Query container logs

Request parameters of DescribeContainerLogRequest

Parameter Type Required Description
ContainerGroupId String Yes The ID of the container group.
ContainerName String Yes The name of the container.
StartTime String No The start time of the operation. Specify the time in the RFC 3339 standard in the yyyy-MM-ddTHH:mm:ssZ format. For example, 2018-08-02T15:00:00Z. The time must be in UTC.
Tail Integer No The number of lines in a log file. Default: 500 lines. Maximum: 2,000 lines.

Response parameters of DescribeContainerLogResponse

Parameter Type Description
RequestId String The ID of the request.
ContainerName String The name of the container.
Content String The content of the log.
Sample code
  1. from aliyunsdkeci.request.v20180808.DescribeContainerLogRequest import DescribeContainerLogRequest
  2. request = DescribeContainerLogRequest()
  3. request.set_ContainerGroupId('eci-xxx')
  4. request.set_ContainerName(ContainerName)
  5. response = eciClient.do_action_with_exception(request)
  6. print response

Output

  1. {"RequestId":"0F333D18-51A0-43D3-A804-120921446EB8","ContainerName":"nginx","Content":"106.11.34.14 - - [27/Nov/2018:07:25:37 +0000] \"GET / HTTP/1.1\" 403 555 \"-\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36\" \"-\"\n2018/11/27 07:25:37 [error] 6#6: *1 directory index of \"/usr/share/nginx/html/\" is forbidden, client: 106.11.34.14, server: localhost, request: \"GET / HTTP/1.1\", host: \"47.99.145.99\"\n2018/11/27 07:27:49 [error] 6#6: *3 directory index of \"/usr/share/nginx/html/\" is forbidden, client: 24.0.70.174, server: localhost, request: \"GET / HTTP/1.0\", host: \"1.2.3.4\"\n24.0.70.174 - - [27/Nov/2018:07:27:49 +0000] \"GET / HTTP/1.0\" 403 153 \"-\" \"-\" \"-\"\n50.29.137.33 - - [27/Nov/2018:07:34:00 +0000] \"GET / HTTP/1.0\" 403 153 \"-\" \"-\" \"-\"\n2018/11/27 07:34:00 [error] 6#6: *4 directory index of \"/usr/share/nginx/html/\" is forbidden, client: 50.29.137.33, server: localhost, request: \"GET / HTTP/1.0\", host: \"1.2.3.4\"\n"}