Operations on ACR with Cloud CLI
This page lists some scripts useful for working with [[azure-container-registry]].
Create ACR
az acr create
  --resource-group <resourceGroup>
  --name <myContainerRegistry>
  --sku BasicResource Group, Name, and Sku are mandatory.
Note:
namemust be lowercase, between 5 and 50 charssku: Basic, Premium, Standard.
It returns the whole structure
{
  "adminUserEnabled": false,
  "anonymousPullEnabled": false,
  "creationDate": "2024-04-02T12:23:11.162737+00:00",
  "dataEndpointEnabled": false,
  "dataEndpointHostNames": [],
  "encryption": {
    "keyVaultProperties": null,
    "status": "disabled"
  },
  "id": "/subscriptions/9d91e956-idsubscription-309a15956a53/resourceGroups/az204-rg/providers/Microsoft.ContainerRegistry/registries/davidebacrcontainer",
  "identity": null,
  "location": "westeurope",
  "loginServer": "davidebacrcontainer.azurecr.io",
  "metadataSearch": "Disabled",
  "name": "davidebacrcontainer",
  "networkRuleBypassOptions": "AzureServices",
  "networkRuleSet": null,
  "policies": {
    "azureAdAuthenticationAsArmPolicy": {
      "status": "enabled"
    },
    "exportPolicy": {
      "status": "enabled"
    },
    "quarantinePolicy": {
      "status": "disabled"
    },
    "retentionPolicy": {
      "days": 7,
      "lastUpdatedTime": "2024-04-02T12:23:18.027167+00:00",
      "status": "disabled"
    },
    "softDeletePolicy": {
      "lastUpdatedTime": "2024-04-02T12:23:18.027203+00:00",
      "retentionDays": 7,
      "status": "disabled"
    },
    "trustPolicy": {
      "status": "disabled",
      "type": "Notary"
    }
  },
  "privateEndpointConnections": [],
  "provisioningState": "Succeeded",
  "publicNetworkAccess": "Enabled",
  "resourceGroup": "az204-rg",
  "sku": {
    "name": "Basic",
    "tier": "Basic"
  },
  "status": null,
  "systemData": {
    "createdAt": "2024-04-02T12:23:11.162737+00:00",
    "createdBy": "d.bel@aaaaa.com",
    "createdByType": "User",
    "lastModifiedAt": "2024-04-02T12:23:11.162737+00:00",
    "lastModifiedBy": "d.bel@aaaaa.com",
    "lastModifiedByType": "User"
  },
  "tags": {},
  "type": "Microsoft.ContainerRegistry/registries",
  "zoneRedundancy": "Disabled"
}Create and push a Docker image
This command reads the content of the Dockerfile, creates an image named sample/hello-world:v1, and pushes it to the Registry.
az acr build
  --image sample/hello-world:v1
  --registry <myContainerRegistry>
  --file Dockerfile
  .You can find the result in the UI:

Show all images under a repository
To show the names of all the images stored in a ACR, you have to use:
az acr repository list
  --name <nome-registry>
  --output tableShow all tags for an image
az acr repository show-tags
  --name <myContainerRegistry>
  --repository sample/hello-world
  --output tableRun a container given its image
az acr run
  --registry <myContainerRegistry>
  --cmd '$Registry/sample/hello-world:v1'
  /dev/nullThe cmd parameter in this example runs the container in its default configuration, but cmd supports other docker run parameters or even other docker commands.
Queue a run to execute a container command:
az acr run -r myregistry --cmd '$Registry/myimage' /dev/nullQueue a run with the task definition from the standard input. Either 'Ctrl + Z'(Windows) or 'Ctrl + D'(Linux) terminates the input stream:
az acr run -r myregistry -f - /dev/nullQueue a run to execute the tasks passed through the pipe:
cat task.yaml | az acr run -r myregistry -f - /dev/nullQueue a local context, pushed to ACR with streaming logs:
az acr run -r myregistry -f bash-echo.yaml ./workspaceQueue a remote git context with streaming logs:
az acr run -r myregistry https://github.com/Azure-Samples/acr-tasks.git -f hello-world.yamlQueue a remote git context with streaming logs and runs the task on Linux platform:
az acr run -r myregistry https://github.com/Azure-Samples/acr-tasks.git -f build-hello-
        world.yaml --platform linuxQueue a remote OCI Artifact context and runs the task:
az acr run -r myregistry oci://myregistry.azurecr.io/myartifact:mytag -f hello-world.yaml