Azure Container Registry image purge is not reflected in SKU - azure

I'm running az acr purge to retain old Docker Images in my ACR.
I can see in the output that tags are being deleted in repository and they are no longer visible in Azure Portal ACR repository explorer.
The problem I'm facing is the SKU usage is not decreasing.
This is one of the many operations that have deleted some docker images.
The command is visible in 2nd line.
Running command on Azure Container Registry
acr purge --filter 'my_docker_repository:(\d+\.\d+.\d+.\d+)-\S*' --ago 180d
2021/08/13 09:48:11 Alias support enabled for version >= 1.1.0, please see https://aka.ms/acr/tasks/task-aliases for more information.
2021/08/13 09:48:11 Creating Docker network: acb_default_network, driver: 'bridge'
2021/08/13 09:48:11 Successfully set up Docker network: acb_default_network
2021/08/13 09:48:11 Setting up Docker configuration...
2021/08/13 09:48:12 Successfully set up Docker configuration
2021/08/13 09:48:12 Logging in to registry: my_very_secret_acr.azurecr.io
2021/08/13 09:48:13 Successfully logged into my_very_secret_acr.azurecr.io
2021/08/13 09:48:13 Executing step ID: acb_step_0. Timeout(sec): 600, Working directory: '', Network: 'acb_default_network'
2021/08/13 09:48:13 Launching container with name: acb_step_0
Deleting tags for repository: my_docker_repository
my_very_secret_acr.azurecr.io/my_docker_repository:2020.12.15.895-RefsPull13776Merge-f101d12
my_very_secret_acr.azurecr.io/my_docker_repository:2021.2.11.1478-IeltsResultsDevelop-0a6c82a
my_very_secret_acr.azurecr.io/my_docker_repository:2021.2.11.1478-RefsPull14181Merge-3c41e76
my_very_secret_acr.azurecr.io/my_docker_repository:2021.2.11.1473-IeltsResultsDevelop-b06f9a3
my_very_secret_acr.azurecr.io/my_docker_repository:2021.2.11.1473-RefsPull14168Merge-1fec456
my_very_secret_acr.azurecr.io/my_docker_repository:2021.2.11.1472-RefsPull14168Merge-0f61afd
my_very_secret_acr.azurecr.io/my_docker_repository:2021.2.11.1463-IeltsResultsDevelop-9a6c4b7
my_very_secret_acr.azurecr.io/my_docker_repository:2021.2.11.1461-RefsPull13734Merge-e0f2caa
my_very_secret_acr.azurecr.io/my_docker_repository:2021.2.11.1461-RefsPull14135Merge-ff95d1f
my_very_secret_acr.azurecr.io/my_docker_repository:2021.2.11.1434-RefsPull13734Merge-20af0dd
Number of deleted tags: 10
Number of deleted manifests: 0
2021/08/13 09:48:14 Successfully executed container: acb_step_0
2021/08/13 09:48:14 Step ID: acb_step_0 marked as successful (elapsed time in seconds: 1.172114)
Run ID: cb7f was successful after 5s
Update #1
Running
az acr repository delete
works like a charm, no modification must be done beforehand
I'm following these guides
Automatically purge images from an Azure container registry

Based on the filter command used ,only tag references are deleted, not the underlying manifests and layer data as it is Write enabled.
acr purge does not delete an image tag or repository where the write-enabled attribute is set to false
az acr repository show \
--name myregistry --image image:tag \
--output jsonc
az acr repository update \
--name myregistry --image myrepo/myimage:tag \
--delete-enabled true --write-enabled true
To delete the image, repository and manifest to free up SKU size . Please follow the link to delete the manifest and data.
Alternatively, if you want to delete the image, tags & manifest using the acr purge you need to pass the acr purge command as an environment variable as explained in the above documentation

Related

How to copy images from GHCR to ACR

Looking for an example in GitHub actions workflow to clone a specifc image name by commit SHA from GHCR (GitHub registry) to ACR (Azure registry) with a need to copy all the tags and labels from the source repository to the target.
At the moment, I'm using Docker pull and push commands, but didn't find a way to fetch all the tags for given image sha from GHCR.
Appreciate your help,
Thanks.
I tried in my environment and got beow results:
To copy Github container registry to azure container registry, You can use the following this command.
Command:
az login
az acr login -n < your acr container registry >
az acr import \
--name <container registry > \
--source <ghcr.io/< username >/image:latest \
--username <Git-hub RegistryUsername> \
--password <Git-hub RegistryPassword>
Console:
Portal:
For more reference:
Import container images - Azure Container Registry | Microsoft Learn

Az acr build command info needed

As per the documentation https://learn.microsoft.com/en-us/azure/container-registry/container-registry-quickstart-task-cli the below command builds and pushes to registry. What if I need only build and then push based on my interest .Because I have to scan image before pushing it.
az acr build --image sample/hello-world:v1
--registry myContainerRegistry008
--file Dockerfile .
Note: There is no docker daemon installed on the system.
As suggested in the Azure Documentation ,You can use --no-push flag in the az acr build command to build the docker file & not to push it to the registry,
Here is the sample output for reference :

Docker commands in Azure

Maybe I do not understand the concept of Azure Container Instances (ACI) and Azure at all correctly. I am using Azure CLI on my Windows-Computer and want to create a Windows-container (core-image) with dockerfile. But there is no AZ command available. I am able to create a container, there is no problem. But not with a dockerfile. Is there a possibility to run docker commands for Azure (Azure CLI, Azure bash, Azure powershell)? Maybe somebody can clarify my misunderstanding.
Many thanks in advance, J.
Of curse, yes, you can use the Azure CLI command to build containers with Dockerfile. But there is a queue for the steps.
The docker image is the first step, you can use the CLI command az acr build to build the image directly in the ACR, with your Dockerfile. For example, the Dockerfile is in your local machine and it's windows image:
az acr build -t sample/hello-world:{{.Run.ID}} -r MyRegistry . --platform windows
The ACI is the second step, CLI command az container create will help you to create the container instance with your images. The example command here:
az container create -g MyResourceGroup --name mywinapp --image winappimage:latest --os-type Windows --cpu 2 --memory 3.5
Once you have your image, you should publish it to Azure Container Registry or Docker Hub.
Take a look on the following links, it provides the information to:
Create a container image for deployment to Azure Container Instances
Deploy the container from Azure Container Registry
Deploy your application
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-tutorial-prepare-app
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-tutorial-prepare-acr
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-tutorial-deploy-app
I have recently done the same thing. I have deployed my windows service to Azure Container Instance through Azure Container Registry. Here is step by step process you need to follow. Before performing these steps you need to have published folder of application. You need to install Docker Desktop in your machine.
Create Dockerfile with below commands and put it inside published folder:
FROM mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2019
COPY . .
ENTRYPOINT Application.exe
Here you need to use base file as per your neeed. You can find Windows base images [here][1]
Now navigate to this directory(published folder path) in Powershell and execute below command:
docker image build -t IMAGE_NAME:TAG . -- name of the image with tag
docker run --rm IMAGE_NAME:TAG -- you can run it locally
Now to push this image to Azure, below are the commands. First login into azure and then azure container registery.
az login -- it will navigate to browser for login
docker login ACR_LOGIN_SERVER_NAME -u ACR_USERNAME --password ACR_PASSWORD
docker tag IMAGE_NAME:TAG ACR_LOGIN_SERVER_NAME/IMAGE_NAME:TAG -- tag local image to azure inside ACR
docker push ACR_LOGIN_SERVER_NAME/IMAGE_NAME:TAG -- push image to ACR
Once you have pushed docker image to ACR, you can see it under Repositories in ACR. Based on this repository, you need to create Azure Container Instance to run your docker image.
To create ACI, click on "Create a resource" and select Containers > Container Instances. Here, you need to key some info like resource group and docker image credentials. Make sure you select Private as Image type and key image registry credentials. This ACI deployment process may take couple of minutes as it will fetch the docker image and then deploy. Once deployment is done, you will see Container running and you can check logs as well.
Hope it helps!!

Deploy image from docker hub to AZure

I want to deploy a image from docker hub to Azure Container Instance.How can we do this.Is it mandatory to push the image first to Azure Container Registry?
All solutions I am getting shows that we need to push the image first to Azure Container Registry.
No, you need not push the image to ACR first, just let the image stay in the docker hub. For example, deploy the Nginx docker image to ACI, the Azure CLI command like below:
az container create -g resourceGroup -n aciName --image nginx --ports 80
As the command shows, you can use the docker image. Actually, the docker hub is the default registry. When you use another registry, you need to add the parameters --registry-login-server, --registry-username and --registry-password. For more details, see az container create.
It also shows clearly in the Azure portal, when you create ACI in the portal, you can see it like below:
You can use docker image directly with the container as follows,
az container create --resource-group myResourceGroup --name mycontainer --image docker image url

imagepullbackoff while pulling image from azure container registry

First i have created the docker image and created kubernetes cluster in azure container service.
Then tag and push the image to my repository, but while pulling my image from azure container registry to kubernetes cluster the pod are created but in status it shows imagepullback off
The yaml file for basic api image
**apiVersion: v1
kind: Pod
metadata:
name: myapis
spec:
containers:
- name: myapis
image: ciqsample.azurecr.io/myapis
imagePullSecrets:
- name: samplekey**
You might need to attach with container registry itself.
az aks update -n myAKSCluster -g myResourceGroup --attach-acr $MYACR
$MYACR -> name of the container registry without ".azurecr.io" postfix
This error means we use wrong key and password to pull image.
Can you run this command to check secret exist or not?kubectl get secret
root#k8s-master-BBF71727-0:~# kubectl get secret
NAME TYPE DATA AGE
azurecr kubernetes.io/dockercfg 1 57m
default-token-clm2d kubernetes.io/service-account-token 3 2h
Then check the secret.
root#k8s-master-BBF71727-0:~# kubectl get secret azurecr --output=yaml
We can use this command script to create secret:
kubectl create secret docker-register yoursecretname --docker-server=jason.azurecr.io/xxxx/test --docker-username={UserName} --docker-password={Password} --docker-email=team#domain.com
By the way, for test please login Azure container registry with your registry credentials, then try to pull image from Azure container registry.
Login
docker login myregistry.azurecr.io -u xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -p myPassword
Pull the image from your registry
docker pull myregistry.azurecr.io/samples/nginx

Resources