快速入門:使用 Azure 入口網站建立私人容器登錄Quickstart: Create a private container registry using the Azure portal

Azure Container Registry 是 Azure 中的私人 Docker 登錄,您可以在其中儲存並管理私人 Docker 容器映像。An Azure container registry is a private Docker registry in Azure where you can store and manage your private Docker container images. 在本快速入門中,您會使用 Azure 入口網站建立容器登錄。In this quickstart, you create a container registry with the Azure portal. 然後,使用 Docker 命令將容器映像推送到登錄中,最後從您的登錄中提取映像並加以執行。Then, use Docker commands to push a container image into the registry, and finally pull and run the image from your registry.

若要登入登錄以使用容器映像,您在進行此快速入門時必須執行 Azure CLI (建議使用 2.0.55 版或更新版本)。To log in to the registry to work with container images, this quickstart requires that you are running the Azure CLI (version 2.0.55 or later recommended). 執行 az --version 以尋找版本。Run az --version to find the version. 如果您需要安裝或升級,請參閱安裝 Azure CLIIf you need to install or upgrade, see Install Azure CLI.

您也必須在本機上安裝 Docker。You must also have Docker installed locally. Docker 提供可輕鬆在 MacWindowsLinux 系統上設定 Docker 的套件。Docker provides packages that easily configure Docker on any Mac, Windows, or Linux system.

登入 AzureSign in to Azure

https://portal.azure.com 登入 Azure 入口網站。Sign in to the Azure portal at https://portal.azure.com.

建立容器登錄庫Create a container registry

選取 [建立資源] > [容器] > [容器登錄]。Select Create a resource > Containers > Container Registry.

在 Azure 入口網站中建立容器登錄

輸入 [登錄名稱] 和 [資源群組] 的值。Enter values for Registry name and Resource group. 登錄名稱在 Azure 內必須是唯一的,且包含 5-50 個英數字元。The registry name must be unique within Azure, and contain 5-50 alphanumeric characters. 在此快速入門中,請在 West US 位置中建立名為 myResourceGroup 的新資源群組,並選取 [基本] 作為 [SKU]。For this quickstart create a new resource group in the West US location named myResourceGroup, and for SKU, select 'Basic'. 選取 [建立] 以部署 ACR 執行個體。Select Create to deploy the ACR instance.

在 Azure 入口網站中建立容器登錄

您在本快速入門中會建立「基本」登錄,這是正在學習 Azure Container Registry 的開發人員所適用的成本最佳化選項。In this quickstart you create a Basic registry, which is a cost-optimized option for developers learning about Azure Container Registry. 如需可用服務層級的詳細資訊,請參閱容器登錄 SKUFor details on available service tiers, see Container registry SKUs.

當 [部署成功] 訊息出現時,請在入口網站中選取容器登錄。When the Deployment succeeded message appears, select the container registry in the portal.

Azure 入口網站中的容器登錄概觀

記下 [登入伺服器] 的值。Take note of the value of the Login server. 您在後續的步驟中透過 Azure CLI 和 Docker 使用登錄時,將會用到此值。You use this value in the following steps while working with your registry with the Azure CLI and Docker.

登入登錄Log in to registry

發送和提取容器映像之前,您必須登入 ACR 執行個體。Before pushing and pulling container images, you must log in to the ACR instance. 在您的作業系統中開啟命令殼層,並在 Azure CLI 中使用 az acr login 命令。Open a command shell in your operating system, and use the az acr login command in the Azure CLI.

az acr login --name <acrName>

完成後,此命令會傳回 Login SucceededThe command returns Login Succeeded once completed.

將映像推送至登錄Push image to registry

若要推送映像到 Azure Container Registry,您必須先有映像。To push an image to an Azure Container registry, you must first have an image. 如果您還沒有任何本機容器映像,請執行下列 docker pull 命令,從 Docker 中樞提取現有的映像。If you don't yet have any local container images, run the following docker pull command to pull an existing image from Docker Hub. 在此範例中,請提取 hello-world 映像。For this example, pull the hello-world image.

docker pull hello-world

您必須使用 ACR 登入伺服器的完整名稱來標記映像,才能將映像推送至您的登錄。Before you can push an image to your registry, you must tag it with the fully qualified name of your ACR login server. 登入伺服器名稱的格式為 <registry-name>.azurecr.io (全部小寫),例如 mycontainerregistry007.azurecr.ioThe login server name is in the format <registry-name>.azurecr.io (all lowercase), for example, mycontainerregistry007.azurecr.io.

使用 docker tag 命令來標記映像。Tag the image using the docker tag command. <acrLoginServer> 取代為 ACR 執行個體的登入伺服器名稱。Replace <acrLoginServer> with the login server name of your ACR instance.

docker tag hello-world <acrLoginServer>/hello-world:v1

最後,使用 docker push 將映像推送到 ACR 執行個體。Finally, use docker push to push the image to the ACR instance. <acrLoginServer> 取代為 ACR 執行個體的登入伺服器名稱。Replace <acrLoginServer> with the login server name of your ACR instance. 此範例會建立 hello-world 存放庫,其中包含 hello-world:v1 映像。This example creates the hello-world repository, containing the hello-world:v1 image.

docker push <acrLoginServer>/hello-world:v1

將映像推送至您的容器登錄之後,請從您的本機 Docker 環境中移除 hello-world:v1 映像。After pushing the image to your container registry, remove the hello-world:v1 image from your local Docker environment. (請注意,此 docker rmi 命令並不會從 Azure 容器登錄中的 hello-world 存放區移除映像。)(Note that this docker rmi command does not remove the image from the hello-world repository in your Azure container registry.)

docker rmi <acrLoginServer>/hello-world:v1

列出容器映像List container images

若要列出您登錄中的映像,請瀏覽至入口網站中的登錄,然後選取 [存放庫],以及選取您使用 docker push 建立的存放庫。To list the images in your registry, navigate to your registry in the portal and select Repositories, then select the repository you created with docker push.

在此範例中,我們選取 hello-world 存放庫,且可以在 TAGS之下看到 v1 標記的映像。In this example, we select the hello-world repository, and we can see the v1-tagged image under TAGS.

列出 Azure 入口網站中的容器映像

從登錄執行映像Run image from registry

現在,您可以使用 docker run 從您的容器登錄中提取 hello-world:v1 容器映像並加以執行:Now, you can pull and run the hello-world:v1 container image from your container registry by using docker run:

docker run <acrLoginServer>/hello-world:v1  

範例輸出︰Example output:

Unable to find image 'mycontainerregistry007.azurecr.io/hello-world:v1' locally
v1: Pulling from hello-world
Digest: sha256:662dd8e65ef7ccf13f417962c2f77567d3b132f12c95909de6c85ac3c326a345
Status: Downloaded newer image for mycontainerregistry007.azurecr.io/hello-world:v1

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

[...]

清除資源Clean up resources

若要清除資源,請在入口網站中瀏覽至 myResourceGroup 資源群組。To clean up your resources, navigate to the myResourceGroup resource group in the portal. 載入資源群組後,按一下 [刪除資源群組] 以移除資源群組、容器登錄,以及儲存於該處的容器映像。Once the resource group is loaded click on Delete resource group to remove the resource group, the container registry, and the container images stored there.

在 Azure 入口網站中刪除資源群組

後續步驟Next steps

在本快速入門中,您已使用 Azure 入口網站建立 Azure Container Registry、推送容器映像,以及從登錄中提取映像並加以執行。In this quickstart, you created an Azure Container Registry with the Azure portal, pushed a container image, and pulled and ran the image from the registry. 請繼續進行 Azure 容器登錄教學課程,以深入了解 ACR。Continue to the Azure Container Registry tutorials for a deeper look at ACR.