Azure Container Instances supports the deployment of multiple containers onto a single host using a container group. A container group is useful when building an application sidecar for logging, monitoring, or any other configuration where a service needs a second attached process.
In this tutorial, you follow steps to run a two-container sidecar configuration by deploying an Azure Resource Manager template using the Azure CLI. 당신은 다음을 배우게 됩니다:
- Configure a multi-container group template
- 컨테이너 그룹 배포
- View the logs of the containers
A Resource Manager template can be readily adapted for scenarios when you need to deploy more Azure service resources (for example, an Azure Files share or a virtual network) with the container group.
비고
Multi-container groups are currently restricted to Linux containers.
Azure를 구독하고 있지 않다면 시작하기 전에 Azure 체험 계정을 만드세요.
필수 조건
Bash 환경을 Azure Cloud Shell에서 사용합니다. 자세한 내용은 Azure Cloud Shell에서 Bash에 대한 빠른 시작을 참조하세요.
CLI 참조 명령을 로컬에서 실행하려면 Azure CLI를 설치하십시오. Windows 또는 macOS에서 실행하는 경우 Docker 컨테이너에서 Azure CLI를 실행하는 것이 좋습니다. 자세한 내용은 Docker 컨테이너에서 Azure CLI를 실행하는 방법을 참조하세요.
로컬 설치를 사용하는 경우 az login 명령을 사용하여 Azure CLI에 로그인합니다. 인증 프로세스를 완료하려면 터미널에 표시되는 단계를 수행합니다. 다른 로그인 옵션은 Azure CLI를 사용하여 로그인을 참조하세요.
메시지가 표시되면 처음 사용할 때 Azure CLI 확장을 설치합니다. 확장에 대한 자세한 내용은 Azure CLI에서 확장 사용을 참조하세요.
az version을 실행하여 설치된 버전과 관련 종속 라이브러리를 확인합니다. 최신 버전으로 업그레이드하려면 az upgrade를 실행합니다.
Configure a template
Start by copying the following JSON into a new file named azuredeploy.json
. Azure Cloud Shell에서 Visual Studio Code를 사용하여 작업 디렉터리에 파일을 만들 수 있습니다.
code azuredeploy.json
This Resource Manager template defines a container group with two containers, a public IP address, and two exposed ports. The first container in the group runs an internet-facing web application. The second container, the sidecar, makes an HTTP request to the main web application via the group's local network.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"containerGroupName": {
"type": "string",
"defaultValue": "myContainerGroup",
"metadata": {
"description": "Container Group name."
}
}
},
"variables": {
"container1name": "aci-tutorial-app",
"container1image": "mcr.microsoft.com/azuredocs/aci-helloworld:latest",
"container2name": "aci-tutorial-sidecar",
"container2image": "mcr.microsoft.com/azuredocs/aci-tutorial-sidecar"
},
"resources": [
{
"name": "[parameters('containerGroupName')]",
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2019-12-01",
"___location": "[resourceGroup().___location]",
"properties": {
"containers": [
{
"name": "[variables('container1name')]",
"properties": {
"image": "[variables('container1image')]",
"resources": {
"requests": {
"cpu": 1,
"memoryInGb": 1.5
}
},
"ports": [
{
"port": 80
},
{
"port": 8080
}
]
}
},
{
"name": "[variables('container2name')]",
"properties": {
"image": "[variables('container2image')]",
"resources": {
"requests": {
"cpu": 1,
"memoryInGb": 1.5
}
}
}
}
],
"osType": "Linux",
"ipAddress": {
"type": "Public",
"ports": [
{
"protocol": "tcp",
"port": 80
},
{
"protocol": "tcp",
"port": 8080
}
]
}
}
}
],
"outputs": {
"containerIPv4Address": {
"type": "string",
"value": "[reference(resourceId('Microsoft.ContainerInstance/containerGroups/', parameters('containerGroupName'))).ipAddress.ip]"
}
}
}
To use a private container image registry, add an object to the JSON document with the following format. For an example implementation of this configuration, see the ACI Resource Manager template reference documentation.
"imageRegistryCredentials": [
{
"server": "[parameters('imageRegistryLoginServer')]",
"username": "[parameters('imageRegistryUsername')]",
"password": "[parameters('imageRegistryPassword')]"
}
]
템플릿 배포
az group create 명령을 사용하여 리소스 그룹을 만듭니다.
az group create --name myResourceGroup --___location eastus
Deploy the template with the az deployment group create command.
az deployment group create --resource-group myResourceGroup --template-file azuredeploy.json
몇 초 정도 지나면 Azure에서 초기 응답이 수신됩니다.
배포 상태 확인
배포 상태를 확인하려면 다음 az container show 명령을 사용합니다.
az container show --resource-group myResourceGroup --name myContainerGroup --output table
If you'd like to view the running application, navigate to its IP address in your browser. For example, the IP is 52.168.26.124
in this example output:
Name ResourceGroup Status Image IP:ports Network CPU/Memory OsType Location
---------------- --------------- -------- -------------------------------------------------------------------------------------------------- -------------------- --------- --------------- -------- ----------
myContainerGroup danlep0318r Running mcr.microsoft.com/azuredocs/aci-tutorial-sidecar,mcr.microsoft.com/azuredocs/aci-helloworld:latest 20.42.26.114:80,8080 Public 1.0 core/1.5 gb Linux eastus
컨테이너 로그 보기
View the log output of a container using the az container logs command. The --container-name
argument specifies the container from which to pull logs. In this example, the aci-tutorial-app
container is specified.
az container logs --resource-group myResourceGroup --name myContainerGroup --container-name aci-tutorial-app
출력:
listening on port 80
::1 - - [02/Jul/2020:23:17:48 +0000] "HEAD / HTTP/1.1" 200 1663 "-" "curl/7.54.0"
::1 - - [02/Jul/2020:23:17:51 +0000] "HEAD / HTTP/1.1" 200 1663 "-" "curl/7.54.0"
::1 - - [02/Jul/2020:23:17:54 +0000] "HEAD / HTTP/1.1" 200 1663 "-" "curl/7.54.0"
To see the logs for the sidecar container, run a similar command specifying the aci-tutorial-sidecar
container.
az container logs --resource-group myResourceGroup --name myContainerGroup --container-name aci-tutorial-sidecar
출력:
Every 3s: curl -I http://localhost 2020-07-02 20:36:41
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 1663 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
HTTP/1.1 200 OK
X-Powered-By: Express
Accept-Ranges: bytes
Cache-Control: public, max-age=0
Last-Modified: Wed, 29 Nov 2017 06:40:40 GMT
ETag: W/"67f-16006818640"
Content-Type: text/html; charset=UTF-8
Content-Length: 1663
Date: Thu, 02 Jul 2020 20:36:41 GMT
Connection: keep-alive
As you can see, the sidecar is periodically making an HTTP request to the main web application via the group's local network to ensure it runs. This sidecar example could be expanded to trigger an alert if it received an HTTP response code other than 200 OK
.
다음 단계
In this tutorial, you used an Azure Resource Manager template to deploy a multi-container group in Azure Container Instances. 당신은 다음을 배우셨습니다:
- Configure a multi-container group template
- 컨테이너 그룹 배포
- View the logs of the containers
For more template samples, see Azure Resource Manager templates for Azure Container Instances.
You can also specify a multi-container group using a YAML file. Due to the YAML format's more concise nature, deployment with a YAML file is a good choice when your deployment includes only container instances.