Azure Container Registry SDK for JavaScript
The Azure Container Registry (ACR) SDK for JavaScript provides a comprehensive set of tools to interact with your Azure Container Registry instances from your JavaScript applications. This SDK allows you to programmatically manage repositories, tags, manifest, and blobs within your registry.
With the ACR SDK, you can:
- Authenticate with your Azure Container Registry.
- List, retrieve, and delete repositories.
- Manage image tags and associated manifests.
- Upload and download container image layers (blobs).
- Generate and manage content trust signing keys.
- Perform various administrative tasks on your registry.
Key Features
Repository Management
Create, list, get details, and delete container repositories.
Tag and Manifest Operations
Manage image tags, retrieve manifest information (OCI, Docker V2), and delete specific image versions.
Blob Storage Access
Upload and download container image layers and other artifacts securely.
Authentication Support
Integrates seamlessly with Azure Identity for robust and secure authentication methods.
Content Trust
Supports signing and verifying container images for enhanced security.
Cross-Platform Compatibility
Works in Node.js environments and modern web browsers.
Install the SDK
You can install the Azure Container Registry SDK for JavaScript using npm or yarn.
npm install @azure/container-registry
or
yarn add @azure/container-registry
Getting Started
Here's a quick guide to get you started with the Azure Container Registry SDK.
1. Authentication
You'll need to authenticate your application to access your Azure Container Registry. The recommended approach is to use Azure Identity credentials.
import { ContainerRegistryClient } from "@azure/container-registry";
import { DefaultAzureCredential } from "@azure/identity";
// Replace with your registry name
const registryName = "your-registry-name.azurecr.io";
async function main() {
const credential = new DefaultAzureCredential();
const client = new ContainerRegistryClient(registryName, credential);
console.log("Successfully created Container Registry client.");
// Further operations will go here...
}
main().catch((err) => {
console.error("The following error occurred: ", err);
process.exit(1);
});
2. Listing Repositories
Once authenticated, you can start interacting with your registry. Here's how to list all repositories:
import { ContainerRegistryClient } from "@azure/container-registry";
import { DefaultAzureCredential } from "@azure/identity";
const registryName = "your-registry-name.azurecr.io";
async function listRepositories() {
const credential = new DefaultAzureCredential();
const client = new ContainerRegistryClient(registryName, credential);
console.log("Listing repositories:");
for await (const repositoryProperties of client.listRepositoryProperties()) {
console.log(`- ${repositoryProperties.name}`);
}
}
listRepositories().catch((err) => {
console.error("Error listing repositories: ", err);
});
Usage Examples
3. Retrieving Repository Manifests
Get detailed information about the manifests within a specific repository:
import { ContainerRegistryClient } from "@azure/container-registry";
import { DefaultAzureCredential } from "@azure/identity";
const registryName = "your-registry-name.azurecr.io";
const repositoryName = "my-app"; // e.g., "my-app"
async function getManifests() {
const credential = new DefaultAzureCredential();
const client = new ContainerRegistryClient(registryName, credential);
console.log(`Manifests for repository "${repositoryName}":`);
for await (const manifestProperties of client.listManifestProperties(repositoryName)) {
console.log(`- Tag: ${manifestProperties.tags.join(', ') || 'N/A'}, Digest: ${manifestProperties.digest}`);
}
}
getManifests().catch((err) => {
console.error("Error getting manifests: ", err);
});
4. Deleting an Image Tag
Remove a specific image tag and its associated manifest and layers:
import { ContainerRegistryClient } from "@azure/container-registry";
import { DefaultAzureCredential } from "@azure/identity";
const registryName = "your-registry-name.azurecr.io";
const repositoryName = "my-app";
const tagToDelete = "latest"; // The tag to delete
async function deleteImage() {
const credential = new DefaultAzureCredential();
const client = new ContainerRegistryClient(registryName, credential);
console.log(`Deleting image tag "${tagToDelete}" from repository "${repositoryName}"...`);
try {
await client.deleteManifest(repositoryName, `${repositoryName}:${tagToDelete}`);
console.log(`Successfully deleted image with tag "${tagToDelete}".`);
} catch (error) {
console.error(`Failed to delete image with tag "${tagToDelete}": `, error);
}
}
deleteImage().catch((err) => {
console.error("Error deleting image: ", err);
});
API Reference
Explore the detailed API reference for the Azure Container Registry SDK for JavaScript.
Core Clients
Models
- RepositoryProperties
- ManifestProperties
- ArtifactMimeType
- ArtifactArchitecture
- ArtifactOperatingSystem
Operations
For a complete API reference, please visit the official Azure SDK documentation.
Contributing
We welcome contributions to the Azure SDK for JavaScript! You can find more information on how to contribute, report issues, and suggest features in our CONTRIBUTING.md file on GitHub.
Support and Feedback
If you encounter any issues or have feedback, please open an issue on our GitHub repository.