共用方式為


Docker@0 - Docker v0 工作

建置、標記、推送、執行 Docker 映像,或執行 Docker 命令。 搭配 Docker 或 Azure Container Registry 使用此工作。

注意

Docker@2 是這個工作的較新版本,可藉由移除可當做自變數傳遞至命令的輸入來簡化工作。

Syntax

# 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.
# 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. 
  # 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.
# Docker v0
# Build, tag, push, or run Docker images, or run a Docker command. Task can be used with Docker or Azure Container registry.
- 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. 
  # 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 RegistryContainer Registry。 預設值:Azure Container Registry

選取 [Azure Container Registry],以使用 Azure 服務連線來連線到它。 選取 [容器登錄] 以連線至 Docker Hub 或任何其他私人容器登錄。


dockerRegistryConnection - Docker Registry 服務連線
輸入別名: dockerRegistryEndpointstring. 選擇性。 使用 時 containerregistrytype = Container Registry

指定 Docker 登錄服務連線。 需要向登錄進行驗證的命令所需。


azureSubscription - Azure 訂用帳戶
輸入別名: azureSubscriptionEndpointstring. 選擇性。 使用 時 containerregistrytype = Azure Container Registry

指定 Azure 訂用帳戶。


azureContainerRegistry - Azure Container Registry
string. 選擇性。 使用 時 containerregistrytype = Azure Container Registry

指定所選 Azure 訂用帳戶中的 Azure Container Registry。 容器映像會建置並推送至此容器登錄。


action - 行動
string. 必要。 允許的值:Build an image、、、Push an imageTag imagesPush imagesRun an image、、 Run a Docker command。 預設值:Build an image

指定 Docker 動作。


dockerFile - Docker 檔案
string. 當 action = Build an image 時為必要。 預設值:**/Dockerfile

指定 Docker 檔案的路徑。 工作會使用它找到的第一個 Docker 檔案來建置映像。


addBaseImageData - 將基底映像元數據新增至映像 ()
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 應用程式,您可以指定 python app.py 來啟動 Web 應用程式。


detached - 在背景中執行
boolean. 選擇性。 使用時機 action = Run an image。 預設值:true

指定是否要在背景執行 Docker 容器。


restartPolicy - 重新啟動原則
string. 當 action = Run an image && detached = true 時為必要。 允許的值:noonFailure (失敗) 、 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 - 工作目錄
輸入別名: cwdstring. 預設值:$(System.DefaultWorkingDirectory)

指定 Docker 命令的工作目錄。


memory - 記憶體限制
string.

指定容器可用的記憶體數量上限,做為具有選擇性後綴的整數,例如 2GB


工作控制選項

除了工作輸入之外,所有工作都有控制選項。 如需詳細資訊,請參閱 控件選項和一般工作屬性

輸出變數

此工作會定義下列 輸出變數,您可以在下游步驟、作業和階段中取用這些變數。

DockerOutput
儲存 docker 命令的輸出。

DockerOutputPath
檔案的路徑,其中包含建置命令的輸出。

此工作會定義下列 輸出變數,您可以在下游步驟、作業和階段中取用這些變數。

DockerOutput
儲存 docker 命令的輸出

備註

Docker@2 是較新版本的工作,可藉由移除可當做自變數傳遞至命令的輸入來簡化工作。

規格需求

需求 描述
管線類型 YAML、傳統組建、傳統版本
執行於 Agent、DeploymentGroup
要求
Capabilities 此工作不符合作業中後續工作的任何需求。
命令限制 任何
Settable 變數 任何
代理程式版本 所有支援的代理程式版本。
工作類別 建置

另請參閱