建置、標記、推送、執行 Docker 映像,或執行 Docker 命令。 將此工作與 Docker 或 Azure Container Registry 搭配使用。
備註
Docker@2 是這個工作的較新版本,可藉由移除可當做自變數傳遞至命令的輸入來簡化工作。
建置、標記、推送、執行 Docker 映像,或執行 Docker 命令。 將此工作與 Docker 或 Azure Container Registry 搭配使用。
備註
Docker@2 是這個工作的較新版本,可藉由移除可當做自變數傳遞至命令的輸入來簡化工作。
語法
# Docker v0
# Build, tag, push, or run Docker images, or run a Docker command.
- task: Docker@0
inputs:
containerregistrytype: 'Azure Container Registry' # 'Azure Container Registry' | 'Container Registry'. Required. Container Registry Type. Default: Azure Container Registry.
#dockerRegistryConnection: # string. Alias: dockerRegistryEndpoint. Optional. Use when containerregistrytype = Container Registry. Docker Registry Service Connection.
#azureSubscription: # string. Alias: azureSubscriptionEndpoint. Optional. Use when containerregistrytype = Azure Container Registry. Azure subscription.
#azureContainerRegistry: # string. Optional. Use when containerregistrytype = Azure Container Registry. Azure Container Registry.
action: 'Build an image' # 'Build an image' | 'Tag images' | 'Push an image' | 'Push images' | 'Run an image' | 'Run a Docker command'. Required. Action. Default: Build an image.
#dockerFile: '**/Dockerfile' # string. Required when action = Build an image. Docker File. Default: **/Dockerfile.
#buildArguments: # string. Optional. Use when action = Build an image. Build Arguments.
#defaultContext: true # boolean. Optional. Use when action = Build an image. Use Default Build Context. Default: true.
#context: # string. Optional. Use when action = Build an image && defaultContext = false. Build Context.
#imageName: '$(Build.Repository.Name):$(Build.BuildId)' # string. Required when action == Build an image || action == Push an image || action == Run an image. Image Name. Default: $(Build.Repository.Name):$(Build.BuildId).
#imageNamesPath: # string. Required when action == Tag images || action == Push images. Image Names Path.
#qualifyImageName: true # boolean. Optional. Use when action = Build an image || action = Tag images || action = Push an image || action = Push images || action = Run an image. Qualify Image Name. Default: true.
#additionalImageTags: # string. Optional. Use when action = Build an image || action = Tag images || action = Push an image || action = Push images. Additional Image Tags.
#includeSourceTags: false # boolean. Optional. Use when action = Build an image || action = Tag image || action = Push an image || action = Push images. Include Source Tags. Default: false.
#includeLatestTag: false # boolean. Optional. Use when action = Build an image || action = Push an image || action = Push images. Include Latest Tag. Default: false.
#imageDigestFile: # string. Optional. Use when action = Push an image || action = Push images. Image Digest File.
#containerName: # string. Optional. Use when action = Run an image. Container Name.
#ports: # string. Optional. Use when action = Run an image. Ports.
#volumes: # string. Optional. Use when action = Run an image. Volumes.
#envVars: # string. Optional. Use when action = Run an image. Environment Variables.
#workDir: # string. Optional. Use when action = Run an image. Working Directory.
#entrypoint: # string. Optional. Use when action = Run an image. Entry Point Override.
#containerCommand: # string. Optional. Use when action = Run an image. Command.
#detached: true # boolean. Optional. Use when action = Run an image. Run In Background. Default: true.
#restartPolicy: 'no' # 'no' | 'onFailure' | 'always' | 'unlessStopped'. Required when action = Run an image && detached = true. Restart Policy. Default: no.
#restartMaxRetries: # string. Optional. Use when action = Run an image && detached = true && restartPolicy = onFailure. Maximum Restart Retries.
#customCommand: # string. Required when action = Run a Docker command. Command.
# commands
#addBaseImageData: true # boolean. Add base image metadata to image(s). Default: true.
# Advanced Options
#dockerHostEndpoint: # string. Docker Host Service Connection.
#enforceDockerNamingConvention: true # boolean. Force image name to follow Docker naming convention. Default: true.
#workingDirectory: '$(System.DefaultWorkingDirectory)' # string. Alias: cwd. Working Directory. Default: $(System.DefaultWorkingDirectory).
#memory: # string. Memory limit.
輸入
containerregistrytype
-
Container Registry 類型
string。 必須的。 允許的值:Azure Container Registry、Container Registry。 預設值:Azure Container Registry。
選取 [Azure Container Registry] 以使用 Azure 服務聯機來連線到它。 選取 [容器登錄] 以連線到 Docker Hub 或任何其他私人容器登錄。
dockerRegistryConnection
-
Docker Registry Service 連線
輸入別名: dockerRegistryEndpoint。
string。 選擇性。
containerregistrytype = Container Registry時使用 。
指定 Docker 登錄服務連線。 需要用於需要向登錄進行驗證的命令。
azureSubscription
-
Azure 訂用帳戶
輸入別名: azureSubscriptionEndpoint。
string。 選擇性。
containerregistrytype = Azure Container Registry時使用 。
指定 Azure 訂用帳戶。
azureContainerRegistry
-
Azure 容器註冊表
string。 選擇性。
containerregistrytype = Azure Container Registry時使用 。
指定所選 Azure 訂用帳戶中的 Azure Container Registry。 容器映像會建置並推送至此容器登錄。
action
-
動作
string。 必須的。 允許的值:Build an image、Tag images、Push an image、Push images、Run an imageRun a Docker command。 預設值:Build an image。
指定 Docker 動作。
dockerFile
-
Docker 檔案
string。
action = Build an image時為必要項。 預設值:**/Dockerfile。
指定 Docker 檔案的路徑。 工作會使用它找到的第一個 Docker 檔案來建置映像。
addBaseImageData
-
將基底映射元數據新增至 image(s)
boolean。 預設值:true。
默認值會新增基底映射數據,例如基底映像名稱和摘要,以協助追蹤。 您可以將 值設定為 false,以退出宣告。
buildArguments
-
建置自變數
string。 選擇性。
action = Build an image時使用 。
指定 Docker 檔案的建置時間變數。 在新行上格式化每個 name=value 組。
defaultContext
-
使用預設建置內容
boolean。 選擇性。
action = Build an image時使用 。 預設值:true。
指定包含 Docker 檔案之目錄的組建內容。
context
-
建置內容
string。 選擇性。
action = Build an image && defaultContext = false時使用 。
指定建置內容的路徑。
imageName
-
映射名稱
string。
action == Build an image || action == Push an image || action == Run an image時為必要項。 預設值:$(Build.Repository.Name):$(Build.BuildId)。
指定要建置、推送或執行之 Docker 映像的名稱。
imageNamesPath
-
映射名稱路徑
string。
action == Tag images || action == Push images時為必要項。
指定要標記或推送之 Docker 映像名稱的文字文件路徑。 列出個別行上的每個影像名稱。
qualifyImageName
-
限定映像名稱
boolean。 選擇性。
action = Build an image || action = Tag images || action = Push an image || action = Push images || action = Run an image時使用 。 預設值:true。
使用 Docker 登錄服務連線的主機名來指定限定映像名稱。
additionalImageTags
-
其他影像標記
string。 選擇性。
action = Build an image || action = Tag images || action = Push an image || action = Push images時使用 。
指定要建置或推送之 Docker 映像的其他標籤。
includeSourceTags
-
包含來源標籤
boolean。 選擇性。
action = Build an image || action = Tag image || action = Push an image || action = Push images時使用 。 預設值:false。
指定在建置或推送 Docker 映射時,是否要包含 Git 標籤。
includeLatestTag
-
包含最新的標籤
boolean。 選擇性。
action = Build an image || action = Push an image || action = Push images時使用 。 預設值:false。
指定在建置或推送 Docker 映射時,是否要包含 最新的 標籤。
imageDigestFile
-
影像摘要檔案
string。 選擇性。
action = Push an image || action = Push images時使用 。
指定檔案的路徑,該檔案已建立並填入已推送之 Docker 映射的完整映像存放庫摘要。
containerName
-
容器名稱
string。 選擇性。
action = Run an image時使用 。
指定要執行的 Docker 容器名稱。
ports
-
埠
string。 選擇性。
action = Run an image時使用 。
指定要發佈至主機之 Docker 容器中的埠。 列出新行上的每個 host-port:container-port 系結。
volumes
-
磁碟區
string。 選擇性。
action = Run an image時使用 。
指定要從主機掛接的磁碟區。 列出新行中的每個 host-dir:container-dir。
envVars
-
環境變數
string。 選擇性。
action = Run an image時使用 。
指定 Docker 容器的環境變數。 列出新行上每個 name=value 組。
workDir
-
工作目錄
string。 選擇性。
action = Run an image時使用 。
指定 Docker 容器的工作目錄。
entrypoint
-
進入點覆寫
string。 選擇性。
action = Run an image時使用 。
指定 Docker 容器的預設進入點覆寫。
containerCommand
-
命令
string。 選擇性。
action = Run an image時使用 。
指定 Docker 執行命令。 docker run 命令會先在指定的映像上建立可寫入的容器層,然後使用指定的執行命令加以啟動。 例如,如果映像包含簡單的 Python Flask Web 應用程式,您可以指定要啟動 Web 應用程式的 python app.py。
在背景中執行 detached -
boolean。 選擇性。
action = Run an image時使用 。 預設值:true。
指定是否要在背景中執行 Docker 容器。
restartPolicy
-
重新啟動原則
string。
action = Run an image && detached = true時為必要項。 允許的值:no、onFailure(失敗時)、alwaysunlessStopped(除非停止)。 預設值:no。
指定重新啟動原則。
restartMaxRetries
-
重新啟動重試次數上限
string。 選擇性。
action = Run an image && detached = true && restartPolicy = onFailure時使用 。
指定 Docker 精靈嘗試的重新啟動重試次數上限。
customCommand
-
命令
string。
action = Run a Docker command時為必要項。
指定要執行的 Docker 命令和自變數。 例如,rmi -f image-name 移除映像。
dockerHostEndpoint
-
Docker 主機服務連線
string。
指定 Docker 主機服務連線。 預設為代理程式的主機。
enforceDockerNamingConvention
-
強制映像名稱遵循 Docker 命名慣例
boolean。 預設值:true。
如果啟用,請根據 Docker 命名慣例修改 Docker 映像名稱。 例如,將大寫字元轉換成小寫,並移除空格。
workingDirectory
-
工作目錄
輸入別名: cwd。
string。 預設值:$(System.DefaultWorkingDirectory)。
指定 Docker 命令的工作目錄。
memory
-
記憶體限制
string。
使用選擇性後綴指定容器可用的記憶體數量上限,例如 2GB。
工作控制選項
除了工作輸入之外,所有工作都有控制選項。 如需詳細資訊,請參閱 控制項選項和一般工作屬性。
輸出變數
此工作會定義下列 輸出變數,您可以在下游步驟、作業和階段中取用這些變數。
DockerOutput
儲存 docker 命令的輸出。
DockerOutputPath
檔案的路徑,其中包含建置命令的輸出。
備註
Docker@2 是這個工作的較新版本,可藉由移除可當做自變數傳遞至命令的輸入來簡化工作。
需求
| 要求 | 說明 |
|---|---|
| 管線類型 | YAML、傳統組建、傳統版本 |
| 執行於 | Agent、DeploymentGroup |
| 需求 | 沒有 |
| 功能 | 此工作不符合作業中後續工作的任何需求。 |
| 命令限制 | 任意 |
| Settable 變數 | 任意 |
| 代理程式版本 | 所有支援的代理程式版本。 |
| 工作類別 | 建造 |