Hi @Antonios Inglezakis ,
Apologies for the delay in response. I was trying out hands-on lab to implement the above scenario.
So as per your requirement, I understand you want to make the two containers within a container group talk to each other but internal dns resolution cannot happen with container name in Azure container instances(ACI), neither can it happen with hostname because the hostname of the container instances within container group is same. This is by design, and the workaround is to use localhost:port on which the corresponding application is serving to communicate between the two containers.
For example, lets' say you have a container group called myContainerGroup in which there are two container instances: aci-tutorial-app and aci-tutorial-sidecar. Below is the deployment (ARM) template for the myContainerGroup.
{
"$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
}
],
"dnsNameLabel": "container-test2"
}
}
}
],
"outputs": {
"containerIPv4Address": {
"type": "string",
"value": "[reference(resourceId('Microsoft.ContainerInstance/containerGroups/', parameters('containerGroupName'))).ipAddress.ip]"
}
}
}
Now, the container aci-tutorial-app has two ports exposed, port 80 and port 8080, whereas container aci-tutorial-sidecar has no ports exposed. There is a FQDN/dnsNameLabel set for the container group in the template. The FQDN is container-test2.eastus.azurecontainer.io.
When I exec into both the containers with the bellow commands:
az container exec -g myResourceGroup -n myContainerGroup --container-name aci-tutorial-app --exec-command sh
az container exec -g myResourceGroup -n myContainerGroup --container-name aci-tutorial-sidecar --exec-command sh
Once you exec into both these container instances via Azure cli/cloud shell, you can do a ifconfig and see that the private ip is same for both container instances. Also, the hostname will be same as well. So, in this scenario you can make both the container instances reach each other via localhost on any port even if those ports aren't exposed externally on the group's IP address.
Reference link: https://learn.microsoft.com/en-us/azure/container-instances/container-instances-multi-container-group
I hope this helps. Please don't forget to upvote and accept as answer if you think my response was helpful, so that it can help others in the community looking for help on similar issues.