다음을 통해 공유


빠른 시작: Azure Container Registry 작업을 사용하여 컨테이너 이미지 빌드 및 실행

이 빠른 시작에서는 Azure Container Registry 작업 명령을 사용하여 로컬 Docker 설치 없이 Azure 내에서 기본적으로 Docker 컨테이너 이미지를 신속하게 빌드, 푸시 및 실행합니다. ACR 작업은 컨테이너 수명 주기 동안 컨테이너 이미지를 관리하고 수정하는 데 도움이 되는 Azure Container Registry 내의 기능 모음입니다. 이 예제에서는 로컬 Dockerfile을 사용하여 주문형 빌드를 사용하여 "내부 루프" 컨테이너 이미지 개발 주기를 클라우드로 오프로드하는 방법을 보여 줍니다.

이 빠른 시작 후에 ACR 작업의 고급 기능을 탐색하려면 자습서를 사용하세요. ACR 작업은 코드 커밋 또는 기본 이미지 업데이트를 기반으로 이미지 빌드를 자동화하거나 여러 컨테이너를 병렬로 테스트할 수 있습니다.

Azure 계정이 없는 경우 시작하기 전에 체험 계정을 만듭니다.

필수 조건

  • 이 빠른 시작에는 Azure CLI 버전 2.0.58 이상이 필요합니다. Azure Cloud Shell을 사용하는 경우 최신 버전이 이미 설치되어 있습니다.

리소스 그룹 만들기

컨테이너 레지스트리가 아직 없는 경우 먼저 az group create 명령을 사용하여 리소스 그룹을 만듭니다. Azure 리소스 그룹은 Azure 리소스가 배포 및 관리되는 논리적 컨테이너입니다.

다음 예제에서는 eastus 위치에 myResourceGroup이라는 리소스 그룹을 만듭니다.

az group create --name myResourceGroup --___location eastus

컨테이너 레지스트리 만들기

az acr create 명령을 사용하여 컨테이너 레지스트리를 만듭니다. 레지스트리 이름은 Azure 내에서 고유해야 하며 5-50자의 영숫자를 포함해야 합니다. 다음 예제에서는 mycontainerregistry008 이 사용됩니다. 이를 고유한 값으로 업데이트합니다.

az acr create --resource-group myResourceGroup \
  --name mycontainerregistry008 --sku Basic

이 예제에서는 Azure Container Registry에 대해 학습하는 개발자를 위한 비용 최적화 옵션인 기본 레지스트리를 만듭니다. 사용 가능한 서비스 계층에 대한 자세한 내용은 컨테이너 레지스트리 서비스 계층을 참조하세요.

Dockerfile에서 이미지 빌드 및 푸시

이제 Azure Container Registry를 사용하여 이미지를 빌드하고 푸시합니다. 먼저 로컬 작업 디렉터리를 만든 다음, 한 줄FROM mcr.microsoft.com/hello-worldDockerfile이라는 Dockerfile을 만듭니다. Microsoft Container Registry에서 호스트되는 이미지에서 Linux 컨테이너 이미지를 빌드하는 hello-world 간단한 예제입니다. 고유한 표준 Dockerfile을 만들고 다른 플랫폼에 대한 이미지를 빌드할 수 있습니다. bash 셸에서 작업하는 경우 다음 명령을 사용하여 Dockerfile을 만듭니다.

echo "FROM mcr.microsoft.com/hello-world" > Dockerfile

이미지를 빌드하고 이미지가 성공적으로 빌드된 후 레지스트리에 푸시하는 az acr build 명령을 실행합니다. 다음 예제에서는 이미지를 빌드하고 푸시합니다 sample/hello-world:v1 . 명령의 끝에는 . Dockerfile의 위치(이 경우 현재 디렉터리)가 설정됩니다.

az acr build --image sample/hello-world:v1 \
  --registry mycontainerregistry008 \
  --file Dockerfile . 

비고

ABAC 사용 원본 레지스트리를 사용하는 경우 호출자의 ID를 레지스트리로 인증하는 데 사용할 build ID로 전달해야 합니다. az acr build을 실행하기 전에 추가 --source-acr-auth-id [caller] 플래그를 전달하여 수행해야 합니다.

자세한 내용은 ACR 작업, 빠른 작업, 빠른 빌드 및 빠른 실행에서 ABAC를 사용하도록 설정하는 효과를 참조하세요.

성공적인 빌드 및 푸시의 출력은 다음과 유사합니다.

Packing source code into tar to upload...
Uploading archived source code from '/tmp/build_archive_b0bc1e5d361b44f0833xxxx41b78c24e.tar.gz'...
Sending context (1.856 KiB) to registry: mycontainerregistry008...
Queued a build with ID: ca8
Waiting for agent...
2019/03/18 21:56:57 Using acb_vol_4c7ffa31-c862-4be3-xxxx-ab8e615c55c4 as the home volume
2019/03/18 21:56:57 Setting up Docker configuration...
2019/03/18 21:56:58 Successfully set up Docker configuration
2019/03/18 21:56:58 Logging in to registry: mycontainerregistry008.azurecr.io
2019/03/18 21:56:59 Successfully logged into mycontainerregistry008.azurecr.io
2019/03/18 21:56:59 Executing step ID: build. Working directory: '', Network: ''
2019/03/18 21:56:59 Obtaining source code and scanning for dependencies...
2019/03/18 21:57:00 Successfully obtained source code and scanned for dependencies
2019/03/18 21:57:00 Launching container with name: build
Sending build context to Docker daemon  13.82kB
Step 1/1 : FROM mcr.microsoft.com/hello-world
latest: Pulling from hello-world
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586fxxxx21577a99efb77324b0fe535
Successfully built fce289e99eb9
Successfully tagged mycontainerregistry008.azurecr.io/sample/hello-world:v1
2019/03/18 21:57:01 Successfully executed container: build
2019/03/18 21:57:01 Executing step ID: push. Working directory: '', Network: ''
2019/03/18 21:57:01 Pushing image: mycontainerregistry008.azurecr.io/sample/hello-world:v1, attempt 1
The push refers to repository [mycontainerregistry008.azurecr.io/sample/hello-world]
af0b15c8625b: Preparing
af0b15c8625b: Layer already exists
v1: digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a size: 524
2019/03/18 21:57:03 Successfully pushed image: mycontainerregistry008.azurecr.io/sample/hello-world:v1
2019/03/18 21:57:03 Step ID: build marked as successful (elapsed time in seconds: 2.543040)
2019/03/18 21:57:03 Populating digests for step ID: build...
2019/03/18 21:57:05 Successfully populated digests for step ID: build
2019/03/18 21:57:05 Step ID: push marked as successful (elapsed time in seconds: 1.473581)
2019/03/18 21:57:05 The following dependencies were found:
2019/03/18 21:57:05
- image:
    registry: mycontainerregistry008.azurecr.io
    repository: sample/hello-world
    tag: v1
    digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a
  runtime-dependency:
    registry: registry.hub.docker.com
    repository: library/hello-world
    tag: v1
    digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
  git: {}

Run ID: ca8 was successful after 10s

이미지 실행

이제 빌드하고 레지스트리에 푸시한 이미지를 빠르게 실행합니다. 여기서 는 az acr run 을 사용하여 컨테이너 명령을 실행합니다. 컨테이너 개발 워크플로에서 이미지를 배포하기 전에 유효성 검사 단계일 수도 있고 , 다단계 YAML 파일에 명령을 포함할 수도 있습니다.

다음 예제에서는 $Registry 사용하여 명령을 실행하는 레지스트리의 엔드포인트를 지정합니다.

az acr run --registry mycontainerregistry008 \
  --cmd '$Registry/sample/hello-world:v1' /dev/null

비고

ABAC 사용 원본 레지스트리를 사용하는 경우 호출자의 ID를 레지스트리로 인증하는 데 사용할 run ID로 전달해야 합니다. az acr run을 실행할 때 추가 --source-acr-auth-id [caller] 플래그를 전달하여 수행해야 합니다.

자세한 내용은 ACR 작업, 빠른 작업, 빠른 빌드 및 빠른 실행에서 ABAC를 사용하도록 설정하는 효과를 참조하세요.

이 예제의 매개 변수는 cmd 기본 구성에서 컨테이너를 실행하지만 cmd 추가 docker run 매개 변수 또는 다른 docker 명령을 지원합니다.

출력은 다음과 유사합니다:

Packing source code into tar to upload...
Uploading archived source code from '/tmp/run_archive_ebf74da7fcb04683867b129e2ccad5e1.tar.gz'...
Sending context (1.855 KiB) to registry: mycontainerre...
Queued a run with ID: cab
Waiting for an agent...
2019/03/19 19:01:53 Using acb_vol_60e9a538-b466-475f-9565-80c5b93eaa15 as the home volume
2019/03/19 19:01:53 Creating Docker network: acb_default_network, driver: 'bridge'
2019/03/19 19:01:53 Successfully set up Docker network: acb_default_network
2019/03/19 19:01:53 Setting up Docker configuration...
2019/03/19 19:01:54 Successfully set up Docker configuration
2019/03/19 19:01:54 Logging in to registry: mycontainerregistry008.azurecr.io
2019/03/19 19:01:55 Successfully logged into mycontainerregistry008.azurecr.io
2019/03/19 19:01:55 Executing step ID: acb_step_0. Working directory: '', Network: 'acb_default_network'
2019/03/19 19:01:55 Launching container with name: acb_step_0

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

2019/03/19 19:01:56 Successfully executed container: acb_step_0
2019/03/19 19:01:56 Step ID: acb_step_0 marked as successful (elapsed time in seconds: 0.843801)

Run ID: cab was successful after 6s

자원을 정리하세요

더 이상 필요 없으면 az group delete 명령을 사용하여 리소스 그룹, 컨테이너 레지스트리 및 저장된 컨테이너 이미지를 제거할 수 있습니다.

az group delete --name myResourceGroup

다음 단계

이 빠른 시작에서는 ACR 작업의 기능을 사용하여 로컬 Docker 설치 없이 Azure 내에서 기본적으로 Docker 컨테이너 이미지를 신속하게 빌드, 푸시 및 실행했습니다. Azure Container Registry 작업 자습서를 계속 진행하여 ACR 작업을 사용하여 이미지 빌드 및 업데이트를 자동화하는 방법을 알아봅니다.