{"id":3501,"date":"2024-12-04T00:49:12","date_gmt":"2024-12-04T06:49:12","guid":{"rendered":"https:\/\/microsoftgeek.com\/?p=3501"},"modified":"2024-12-04T00:50:11","modified_gmt":"2024-12-04T06:50:11","slug":"build-a-docker-image-in-a-self-hosted-agent-running-on-azure-container-instances","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=3501","title":{"rendered":"Build a docker image in a self-hosted agent running on Azure Container Instances"},"content":{"rendered":"\n<p>How can a self-hosted agent running on Azure Container Instances create a docker image? Even while the question may seem simple, it is difficult.<\/p>\n\n\n\n<p>Suppose you\u2019ve already set up a self-hosted agent on an Azure Container Instance (ACR); You run a pipeline with a simple docker image and \u2026 you get the below error:<\/p>\n\n\n\n<p><mark>Unable to locate executable file: \u2018docker\u2019. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.<\/mark><\/p>\n\n\n\n<p>Using ACR you&nbsp;<strong>cannot build a docker image<\/strong>. This operation requires access to Docker API running on the container\u2019s host and executing privileged containers.&nbsp;<strong>Within ACR you cannot access the host<\/strong>, so your build fails.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Solution?<\/h4>\n\n\n\n<p>Like always in the Azure Cloud, there are a few solutions to the issue:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>create a self-hosted agent on a Virtual Machine \u2013 this will work, but you need to maintain VM and set it up.<\/li>\n\n\n\n<li>create a VM scale set \u2013 Azure DevOps is deploying new agents in that approach.<\/li>\n\n\n\n<li>use Azure Container Registry dedicated agent pool \u2013 this enables us to build our docker images in the agents handled by ACR. So you don\u2019t need to setup them up, this is pure Microsoft-owned services.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>The complete pipeline you can find here: <\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/karol-pieciukiewicz\/azure-way\/blob\/main\/03_Terraform_network_restrictions\/3_samples\/azure-pipeline\/docker-build-and-deploy.yml\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/karol-pieciukiewicz\/azure-way\/blob\/main\/03_Terraform_network_restrictions\/3_samples\/azure-pipeline\/docker-build-and-deploy.yml<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Build a Docker image using Azure Container Registry dedicated agent pool<\/h4>\n\n\n\n<p>Firstly you must create a dedicated agent pool. You have two options, create a pool within vnet or not.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#simple agent pool\naz acr agentpool create \\\n    --registry MyRegistry \\\n    --name myagentpool \\\n    --tier S2\n\n#agnet pool with vnet integration\nsubnetId=$(az network vnet subnet show \\\n        --resource-group myresourcegroup \\\n        --vnet-name myvnet \\\n        --name mysubnetname \\\n        --query id --output tsv)\n\naz acr agentpool create \\\n    --registry MyRegistry \\\n    --name myagentpool \\\n    --tier S2 \\\n    --subnet-id $subnetId<\/code><\/pre>\n\n\n\n<p>You have four tiers for the agent pool to choose from:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>S1 \u2013 2 CPU, 3 GB RAM<\/li>\n\n\n\n<li>S2 \u2013 4 CPU, 8 GB RAM<\/li>\n\n\n\n<li>S3 \u2013 8 CPU, 16 GB RAM<\/li>\n\n\n\n<li>I6 \u2013 64 CPU, 216 GB RAM<\/li>\n<\/ul>\n\n\n\n<p>To build a Docker image using ACR dedicated agent pool you need to run the below command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>az acr build --registry $CONTAINERREGISTRY --agent-pool $AGENTPOOLNAME --image $IMAGEREPOSITORY:$TAG .<\/code><\/pre>\n\n\n\n<p>Where:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>CONTAINERREGISTRY \u2013 is the name of your ACR, for example, ACR_NAME.azurecr.io<\/li>\n\n\n\n<li>AGENTPOOLNAME \u2013 is the dedicated agent pool name<\/li>\n\n\n\n<li>IMAGEREPOSITORY \u2013 the name of your image<\/li>\n\n\n\n<li>TAG \u2013 tag for your image<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>How can a self-hosted agent running on Azure Container Instances create a docker image? Even while the question may seem simple, it is difficult. Suppose you\u2019ve already set up a self-hosted agent on an Azure Container Instance (ACR); You run a pipeline with a simple docker image and \u2026 you get the below error: Unable [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69,35,78,77],"tags":[],"class_list":["post-3501","post","type-post","status-publish","format-standard","hentry","category-azure","category-cloud-computing","category-containers","category-devops"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3501"}],"version-history":[{"count":2,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3501\/revisions"}],"predecessor-version":[{"id":3503,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/3501\/revisions\/3503"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}