Docker@2 - Docker v2 작업

Docker 이미지를 빌드 또는 푸시하거나, 로그인 또는 로그아웃하거나, 컨테이너를 시작 또는 중지하거나, Docker 명령을 실행합니다.

Docker 이미지를 빌드하거나 푸시하거나, 로그인하거나 로그아웃하거나, Docker 명령을 실행합니다.

Syntax

# Docker v2
# Build or push Docker images, login or logout, start or stop containers, or run a Docker command.
- task: Docker@2
  inputs:
  # Container Repository
    #containerRegistry: # string. Container registry. 
    #repository: # string. Optional. Use when command != login && command != logout && command != start && command != stop. Container repository. 
  # Commands
    command: 'buildAndPush' # 'buildAndPush' | 'build' | 'push' | 'login' | 'logout' | 'start' | 'stop'. Required. Command. Default: buildAndPush.
    Dockerfile: '**/Dockerfile' # string. Required when command = build || command = buildAndPush. Dockerfile. Default: **/Dockerfile.
    #buildContext: '**' # string. Optional. Use when command = build || command = buildAndPush. Build context. Default: **.
    #tags: '$(Build.BuildId)' # string. Optional. Use when command = build || command = push || command = buildAndPush. Tags. Default: $(Build.BuildId).
    #arguments: # string. Optional. Use when command != login && command != logout && command != buildAndPush. Arguments. 
    #addPipelineData: true # boolean. Add Pipeline metadata to image(s). Default: true.
    #addBaseImageData: true # boolean. Add base image metadata to image(s). Default: true.
    #container: # string. Optional. Use when command = start || command = stop. Container.
# Docker v2
# Build or push Docker images, login or logout, start or stop containers, or run a Docker command.
- task: Docker@2
  inputs:
  # Container Repository
    #containerRegistry: # string. Container registry. 
    #repository: # string. Optional. Use when command != login && command != logout && command != start && command != stop. Container repository. 
  # Commands
    command: 'buildAndPush' # 'buildAndPush' | 'build' | 'push' | 'login' | 'logout' | 'start' | 'stop'. Required. Command. Default: buildAndPush.
    Dockerfile: '**/Dockerfile' # string. Required when command = build || command = buildAndPush. Dockerfile. Default: **/Dockerfile.
    #buildContext: '**' # string. Optional. Use when command = build || command = buildAndPush. Build context. Default: **.
    #tags: '$(Build.BuildId)' # string. Optional. Use when command = build || command = push || command = buildAndPush. Tags. Default: $(Build.BuildId).
    #arguments: # string. Optional. Use when command != login && command != logout && command != buildAndPush. Arguments. 
    #addPipelineData: true # boolean. Add Pipeline metadata to image(s). Default: true.
    #container: # string. Optional. Use when command = start || command = stop. Container.
# Docker v2
# Build or push Docker images, login or logout, or run a Docker command.
- task: Docker@2
  inputs:
  # Container Repository
    #containerRegistry: # string. Container registry. 
    #repository: # string. Optional. Use when command != login && command != logout. Container repository. 
  # Commands
    command: 'buildAndPush' # 'buildAndPush' | 'build' | 'push' | 'login' | 'logout'. Required. Command. Default: buildAndPush.
    Dockerfile: '**/Dockerfile' # string. Required when command = build || command = buildAndPush. Dockerfile. Default: **/Dockerfile.
    #buildContext: '**' # string. Optional. Use when command = build || command = buildAndPush. Build context. Default: **.
    #tags: '$(Build.BuildId)' # string. Optional. Use when command = build || command = push || command = buildAndPush. Tags. Default: $(Build.BuildId).
    #arguments: # string. Optional. Use when command != login && command != logout && command != buildAndPush. Arguments. 
    #addPipelineData: true # boolean. Add Pipeline metadata to image(s). Default: true.
# Docker v2
# Build or push Docker images, login or logout, or run a Docker command.
- task: Docker@2
  inputs:
  # Container Repository
    #containerRegistry: # string. Container registry. 
    #repository: # string. Optional. Use when command != login && command != logout. Container repository. 
  # Commands
    command: 'buildAndPush' # 'buildAndPush' | 'build' | 'push' | 'login' | 'logout'. Required. Command. Default: buildAndPush.
    Dockerfile: '**/Dockerfile' # string. Required when command = build || command = buildAndPush. Dockerfile. Default: **/Dockerfile.
    #buildContext: '**' # string. Optional. Use when command = build || command = buildAndPush. Build context. Default: **.
    #tags: '$(Build.BuildId)' # string. Optional. Use when command = build || command = push || command = buildAndPush. Tags. Default: $(Build.BuildId).
    #arguments: # string. Optional. Use when command != login && command != logout && command != buildAndPush. Arguments.

입력

containerRegistry - 컨테이너 레지스트리
string.

Docker 레지스트리 서비스 연결의 이름입니다. 레지스트리를 사용하여 인증을 수행하는 명령에 필요합니다.


repository - 컨테이너 리포지토리
string. 선택 사항입니다. 을 사용할 때 command != login && command != logout && command != start && command != stop사용합니다.

리포지토리의 이름을 지정합니다.


repository - 컨테이너 리포지토리
string. 선택 사항입니다. 을 사용할 때 command != login && command != logout사용합니다.

리포지토리의 이름을 지정합니다.


command - 명령
string. 필수 요소. 허용되는 값: buildAndPush, , build, pushlogin, logout, , start, stop. 기본값은 buildAndPush입니다.

실행할 Docker 명령을 지정합니다.


command - 명령
string. 필수 요소. 허용되는 값: buildAndPush, build, push, , login. logout 기본값은 buildAndPush입니다.

실행할 Docker 명령을 지정합니다.


Dockerfile - Dockerfile
string. 필요한 경우 command = build || command = buildAndPush입니다. 기본값은 **/Dockerfile입니다.

Docker 파일의 경로를 지정합니다. 작업은 이미지를 빌드하기 위해 찾은 첫 번째 Docker 파일을 사용합니다.


buildContext - 빌드 컨텍스트
string. 선택 사항입니다. 을 사용할 때 command = build || command = buildAndPush사용합니다. 기본값은 **입니다.

빌드 컨텍스트의 경로를 지정합니다. 를 전달 ** 하여 Docker 파일이 포함된 디렉터리를 나타냅니다.


tags - 태그
string. 선택 사항입니다. 을 사용할 때 command = build || command = push || command = buildAndPush사용합니다. 기본값은 $(Build.BuildId)입니다.

쉼표로 구분된 태그 목록을 지정합니다. 이러한 태그는 , pushbuildAndPush 명령에 사용됩니다build.


arguments - 인수
string. 선택 사항입니다. 을 사용할 때 command != login && command != logout && command != buildAndPush사용합니다.

Docker 클라이언트에 전달할 추가 인수를 지정합니다. 명령 매개 변수에 buildAndPush 값을 사용하는 경우 인수 속성은 무시됩니다.

예제: 빌드 명령 사용, --build-arg HTTP_PROXY=http://10.20.30.2:1234 --quiet.


addPipelineData - 이미지에 파이프라인 메타데이터 추가
boolean. 기본값은 true입니다.

기본적으로 원본 분기 이름 또는 빌드 ID와 같은 파이프라인 데이터가 추가되고 추적 가능성에 도움이 됩니다. 예를 들어 이미지를 검사하여 이미지를 빌드한 파이프라인을 확인할 수 있습니다. 이 기본 동작을 옵트아웃할 수 있습니다.


addBaseImageData - 이미지에 기본 이미지 메타데이터 추가
boolean. 기본값은 true입니다.

기본적으로 기본 이미지 이름 또는 다이제스트와 같은 기본 이미지 데이터가 추가되고 추적에 도움이 됩니다. 이 기본 동작을 옵트아웃할 수 있습니다.


container - 컨테이너
string. 선택 사항입니다. 을 사용할 때 command = start || command = stop사용합니다.

시작하거나 중지할 컨테이너 리소스의 이름을 지정합니다. 및 명령과 stop 함께 start 이 명령을 사용합니다.


작업 제어 옵션

모든 작업에는 작업 입력 외에 제어 옵션이 있습니다. 자세한 내용은 컨트롤 옵션 및 일반적인 작업 속성을 참조하세요.

출력 변수

이 작업은 다운스트림 단계, 작업 및 단계에서 사용할 수 있는 다음 출력 변수를 정의합니다.

DockerOutput
명령 출력을 포함하는 파일의 경로를 지정합니다. 명령에 대해 별도의 줄에 두 개의 파일 경로를 나열하고 다른 명령의 buildAndPush 파일 경로 하나를 나열할 수 있습니다.

설명

다음은 스크립트에서 Docker 클라이언트 이진 파일을 직접 사용하는 대신 Docker 작업을 사용할 때의 주요 이점입니다.

  • Docker 레지스트리 서비스 연결과의 통합 - 이 작업을 통해 컨테이너 레지스트리에 연결하기 위해 Docker 레지스트리 서비스 연결을 쉽게 사용할 수 있습니다. 로그인한 후에는 Docker 작업에서 사용하는 로그온을 활용하여 다른 작업 또는 스크립트를 실행하는 후속 작업을 추가할 수 있습니다. 예를 들어 Docker 작업을 사용하여 모든 Azure Container Registry 로그인한 다음 다른 작업 또는 스크립트를 사용하여 이미지를 빌드하고 레지스트리에 푸시합니다.

  • 레이블로 추가된 메타데이터 - 작업은 다음 레이블의 이미지에 추적 가능성 관련 메타데이터를 추가합니다.

    • com.azure.dev.image.build.buildnumber
    • com.azure.dev.image.build.builduri
    • com.azure.dev.image.build.definitionname
    • com.azure.dev.image.build.repository.name
    • com.azure.dev.image.build.repository.uri
    • com.azure.dev.image.build.sourcebranchname
    • com.azure.dev.image.build.sourceversion
    • com.azure.dev.image.release.definitionname
    • com.azure.dev.image.release.releaseid
    • com.azure.dev.image.release.releaseweburl
    • com.azure.dev.image.system.teamfoundationcollectionuri
    • com.azure.dev.image.system.teamproject

문제 해결

Docker 작업이 buildAndPush 명령에 전달된 인수를 무시하는 이유는 무엇인가요?

buildAndPush 명령을 사용하여 구성된 Docker 작업은 전달된 인수가 내부 빌드 및 푸시 명령에 모호해지기 때문에 무시합니다. 명령을 별도의 빌드 및 푸시 단계로 분할하고 적절한 인수를 전달할 수 있습니다. 예를 들어, 이 stackoverflow 게시물을 참조하세요.

DockerV2는 Docker 레지스트리 서비스 연결만 지원하고 ARM 서비스 연결은 지원하지 않습니다. Docker 작업에서 인증에 기존 AZURE SPN(서비스 주체)을 어떻게 사용할 수 있나요?

Azure SPN 자격 증명을 사용하여 Docker 레지스트리 서비스 연결을 만들 수 있습니다. 레지스트리 형식에서 다른 항목을 선택하고 다음과 같이 세부 정보를 제공합니다.

Docker Registry:    Your container registry URL (eg. https://myacr.azurecr.io)
Docker ID:          Service principal client ID
Password:           Service principal key

예제

로그인

다음 YAML 코드 조각은 Docker 레지스트리 서비스 연결을 사용하여 컨테이너 레지스트리 로그온을 보여줍니다.

- task: Docker@2
  displayName: Login to ACR
  inputs:
    command: login
    containerRegistry: dockerRegistryServiceConnection1

빌드 및 푸시

라는 buildAndPush 편리한 명령을 사용하면 단일 명령으로 이미지를 빌드하고 컨테이너 레지스트리에 푸시할 수 있습니다.

다음 YAML 코드 조각은 이미지의 여러 태그를 빌드하고 여러 레지스트리에 푸시하는 예제입니다.

steps:
- task: Docker@2
  displayName: Login to ACR
  inputs:
    command: login
    containerRegistry: dockerRegistryServiceConnection1
- task: Docker@2
  displayName: Login to Docker Hub
  inputs:
    command: login
    containerRegistry: dockerRegistryServiceConnection2
- task: Docker@2
  displayName: Build and Push
  inputs:
    command: buildAndPush
    repository: contosoRepository # username/contosoRepository for DockerHub
    tags: |
      tag1
      tag2

위의 코드 조각에서 이미지 contosoRepository:tag1contosoRepository:tag2 는 및 dockerRegistryServiceConnection2에 해당하는 dockerRegistryServiceConnection1 컨테이너 레지스트리에 빌드되고 푸시됩니다.

인증된 모든 컨테이너 레지스트리를 한 번에 빌드하고 푸시하는 대신 특정 인증된 컨테이너 레지스트리를 빌드하고 푸시하려면 표시된 대로 를 사용하여 입력 command: buildAndPush 을 명시적으로 지정 containerRegistry 합니다.

steps:
- task: Docker@2
  displayName: Build and Push
  inputs:
    command: buildAndPush
    containerRegistry: dockerRegistryServiceConnection1
    repository: contosoRepository
    tags: |
      tag1
      tag2

Logout

다음 YAML 코드 조각은 Docker 레지스트리 서비스 연결을 사용하여 컨테이너 레지스트리에서 로그아웃하는 방법을 보여줍니다.

- task: Docker@2
  displayName: Logout of ACR
  inputs:
    command: logout
    containerRegistry: dockerRegistryServiceConnection1

시작/중지

이 작업을 사용하여 작업 및 서비스 컨테이너를 제어합니다. 이 사용법은 일반적이지 않지만 고유한 상황에서 가끔 사용됩니다.

resources:
  containers:
  - container: builder
    image: ubuntu:18.04
steps:
- script: echo "I can run inside the container (it starts by default)"
  target:
    container: builder
- task: Docker@2
  inputs:
    command: stop
    container: builder
# any task beyond this point would not be able to target the builder container
# because it's been stopped

기타 명령 및 인수

명령 및 인수 입력은 예제와 같이 Docker 클라이언트 이진 파일을 사용하여 빌드 또는 푸시 명령에 대한 추가 인수를 전달하는 데 사용됩니다.

steps:
- task: Docker@2
  displayName: Login to ACR
  inputs:
    command: login
    containerRegistry: dockerRegistryServiceConnection1
- task: Docker@2
  displayName: Build
  inputs:
    command: build
    repository: contosoRepository # username/contosoRepository for DockerHub
    tags: tag1
    arguments: --secret id=mysecret,src=mysecret.txt

참고

인수 입력은 를 제외한 buildAndPush모든 명령에 대해 평가됩니다. buildAndPush는 편의 명령(build뒤에)pusharguments이고, 를 사용하면 입력이 무시됩니다.

요구 사항

요구 사항 Description
파이프라인 유형 YAML, 클래식 빌드, 클래식 릴리스
실행 중 에이전트, DeploymentGroup
요청 없음
Capabilities 이 작업은 작업의 후속 작업에 대한 요구를 충족하지 않습니다.
명령 제한 사항 모두
Settable 변수 모두
에이전트 버전 2.172.0 이상
작업 범주 빌드
요구 사항 Description
파이프라인 유형 YAML, 클래식 빌드, 클래식 릴리스
실행 중 에이전트, DeploymentGroup
요청 없음
Capabilities 이 작업은 작업의 후속 작업에 대한 요구를 충족하지 않습니다.
명령 제한 사항 모두
Settable 변수 모두
에이전트 버전 지원되는 모든 에이전트 버전입니다.
작업 범주 빌드