Docker@2 - Docker v2 작업
Docker 이미지를 빌드하거나 푸시하거나, 로그인 또는 로그아웃하거나, 컨테이너를 시작 또는 중지하거나, Docker 명령을 실행합니다.
Docker 이미지를 빌드하거나 푸시하거나, 로그인 또는 로그아웃하거나, Docker 명령을 실행합니다.
구문론
# 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.
입력
repository
-
컨테이너 리포지토리
string
; 선택 사항.
command != login && command != logout && command != start && command != stop
때 사용합니다.
리포지토리의 이름을 지정합니다.
repository
-
컨테이너 리포지토리
string
; 선택 사항.
command != login && command != logout
때 사용합니다.
리포지토리의 이름을 지정합니다.
command
-
명령
string
; 필수 사항입니다. 허용되는 값: buildAndPush
, build
, push
, login
, logout
, start
, stop
. 기본값은 buildAndPush
입니다.
실행할 Docker 명령을 지정합니다.
command
-
명령
string
; 필수 사항입니다. 허용되는 값: buildAndPush
, build
, push
, login
, logout
. 기본값은 buildAndPush
입니다.
실행할 Docker 명령을 지정합니다.
DockerfileDockerfile
-
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)
입니다.
쉼표로 구분된 태그 목록을 지정합니다. 이러한 태그는 build
, push
및 buildAndPush
명령에 사용됩니다.
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
때 사용합니다.
시작하거나 중지할 컨테이너 리소스의 이름을 지정합니다.
start
및 stop
명령과 함께 이 명령을 사용합니다.
작업 제어 옵션
모든 작업에는 작업 입력 외에 제어 옵션이 있습니다. 자세한 내용은 컨트롤 옵션 및 일반적인 작업 속성참조하세요.
출력 변수
이 작업은 다운스트림 단계, 작업 및 단계에서 사용할 수 있는 다음 출력 변수정의합니다.
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:tag1
및 contosoRepository:tag2
빌드되고 dockerRegistryServiceConnection1
및 dockerRegistryServiceConnection2
해당하는 컨테이너 레지스트리에 푸시됩니다.
인증된 모든 컨테이너 레지스트리를 한 번에 빌드하고 푸시하는 대신 특정 인증된 컨테이너 레지스트리를 빌드하고 푸시하려면 다음과 같이 command: buildAndPush
사용하여 containerRegistry
입력을 명시적으로 지정합니다.
steps:
- task: Docker@2
displayName: Build and Push
inputs:
command: buildAndPush
containerRegistry: dockerRegistryServiceConnection1
repository: contosoRepository
tags: |
tag1
tag2
로그아웃
다음 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
뒤에 push
) arguments
입력이 사용될 때 무시됩니다.