다음을 통해 공유


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

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

이 빠른 시작을 마친 후 자습서를 사용하여 ACR 작업의 고급 기능을 더 살펴보세요. 다양한 시나리오를 지원하는 ACR 작업은 코드 커밋 또는 기본 이미지 업데이트를 기반으로 이미지 빌드를 자동화하거나 여러 컨테이너를 병렬로 테스트할 수 있습니다.

Azure를 구독하고 있지 않다면 시작하기 전에 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-world 단일 줄로 Dockerfile이라는 Dockerfile을 만듭니다. Microsoft Container Registry에서 호스팅되는 hello-world 이미지에서 Linux 컨테이너 이미지를 빌드하는 간단한 예제입니다. 사용자 고유의 표준 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 . 

빌드 및 푸시가 성공하면 다음과 비슷한 출력이 표시됩니다.

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

이 예제의 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 작업으로 이미지 빌드 및 업데이트를 자동화하는 방법을 알아보세요.