本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
在 Amazon ECS 任務定義中將磁碟區組態延至啟動時進行
若要設定 Amazon EBS 磁碟區以連接至任務,您必須在任務定義中指定掛載點組態,並為該磁碟區命名。您也必須將 configuredAtLaunch 設定為 true,因為無法在任務定義中設定 Amazon EBS 磁碟區進行連接。但可在部署期間設定 Amazon EBS 磁碟區進行連接。
若要使用 AWS Command Line Interface (AWS CLI) 註冊任務定義,請將範本儲存為 JSON 檔案,然後將檔案傳遞為 register-task-definition命令的輸入。
若要使用 建立和註冊任務定義 AWS 管理主控台,請參閱 使用主控台建立 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-
類型:物件陣列
必要:否
容器中資料磁碟區的掛載點。此參數會映射至 Docker API 中 create-container 的
Volumes,以及 docker run 的--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 磁碟區。