本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
在 Amazon ECS 任務定義中延遲磁碟區組態以啟動時間
若要設定 Amazon EBS 磁碟區以連接至任務,您必須在任務定義中指定掛載點組態,並命名磁碟區。您也必須將 configuredAtLaunch
設定為 ,true
因為無法在任務定義中為連接設定 Amazon EBS 磁碟區。相反地,Amazon EBS 磁碟區會設定為在部署期間連接。
若要使用 AWS Command Line Interface (AWS CLI) 註冊任務定義,請將範本儲存為 JSON 檔案,然後將檔案傳遞為 register-task-definition
命令的輸入。
若要使用 建立和註冊任務定義 AWS Management Console,請參閱 使用主控台建立 Amazon ECS 任務定義。
下列任務定義顯示任務定義中 mountPoints
和 volumes
物件的語法。如需任務定義參數的詳細資訊,請參閱 Fargate 啟動類型的 Amazon ECS 任務定義參數。若要使用此範例,請以您自己的資訊取代
。user input placeholders
{ "family":
"mytaskdef"
, "containerDefinitions": [ { "name": "nginx
", "image": "public.ecr.aws/nginx/nginx:latest
", "networkMode": "awsvpc", "portMappings": [ { "name": "nginx-80-tcp
", "containerPort": 80, "hostPort": 80, "protocol": "tcp", "appProtocol": "http" } ], "mountPoints": [ { "sourceVolume": "myEBSVolume
", "containerPath": "/mount/ebs
", "readOnly":true
} ] } ], "volumes": [ { "name": "myEBSVolume
", "configuredAtLaunch": true } ], "requiresCompatibilities": [ "FARGATE", "EC2" ], "cpu": "1024", "memory": "3072", "networkMode": "awsvpc" }
{ "family":
"mytaskdef"
, "memory": "4096", "cpu": "2048", "family": "windows-simple-iis-2019-core", "executionRoleArn": "arn:aws:iam::012345678910:role/ecsTaskExecutionRole", "runtimePlatform": {"operatingSystemFamily": "WINDOWS_SERVER_2019_CORE"}, "requiresCompatibilities": ["EC2"] "containerDefinitions": [ { "command": ["New-Item -Path C:\\inetpub\\wwwroot\\index.html -Type file -Value '<html> <head> <title>Amazon ECS Sample App</title> <style>body {margin-top: 40px; background-color: #333;} </style> </head><body> <div style=color:white;text-align:center> <h1>Amazon ECS Sample App</h1> <h2>Congratulations!</h2> <p>Your application is now running on a container in Amazon ECS.</p>'; C:\\ServiceMonitor.exe w3svc"], "entryPoint": [ "powershell", "-Command" ], "essential": true, "cpu": 2048, "memory": 4096, "image": "mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019", "name": "sample_windows_app", "portMappings": [ { "hostPort": 443, "containerPort": 80, "protocol": "tcp" } ], "mountPoints": [ { "sourceVolume": "myEBSVolume
", "containerPath": "drive:\ebs
", "readOnly":true
} ] } ], "volumes": [ { "name": "myEBSVolume
", "configuredAtLaunch": true } ], "requiresCompatibilities": [ "FARGATE", "EC2" ], "cpu": "1024", "memory": "3072", "networkMode": "awsvpc" }
mountPoints
-
類型:物件陣列
必要:否
容器中資料磁碟區的掛載點。此參數會映射至 create-container Docker API
Volumes
中的 ,以及 Docker 執行--volume
的選項。Windows 容器可在
$env:ProgramData
所在的相同磁碟上掛載整個目錄。Windows 容器無法在不同的磁碟機上掛載目錄,而且掛載點無法跨磁碟機使用。您必須指定掛載點,將 Amazon EBS 磁碟區直接連接到 Amazon ECS 任務。sourceVolume
-
類型:字串
必要:是 (當使用
mountPoints
時)要掛載的磁碟區名稱。
containerPath
-
類型:字串
必要:是 (當使用
mountPoints
時)要掛載磁碟區的容器中的路徑。
readOnly
-
類型:布林值
必要:否
如果此數值為
true
,容器擁有磁碟區的唯讀存取權。如果此值為false
,則容器可寫入磁碟區。預設值為false
。對於在執行 Windows 作業系統的 EC2 執行個體上執行的任務,請將 值保留為預設值
false
。
name
-
類型:字串
必要:否
磁碟區名稱。最多允許 255 個字母 (大寫和小寫)、數字、連字號 (
-
) 和底線 (_
)。此名稱會在容器定義mountPoints
物件的sourceVolume
參數中參考。 configuredAtLaunch
-
類型:布林值
必要:是,當您想要使用 將 EBS 磁碟區直接連接到任務時。
指定磁碟區是否可在啟動時設定。設為 時
true
,您可以在執行獨立任務或建立或更新服務時設定磁碟區。設為 時false
,您將無法在任務定義中提供另一個磁碟區組態。必須提供此參數並將其設定為true
,以設定要連接到任務的 Amazon EBS 磁碟區。