This sample demonstrates how to push .NET images to Azure Container Registry (ACR). The instructions are based on the .NET Docker Sample.
These instructions use the Azure CLI and the Docker client.
Similar instructions are also available to push to DockerHub.
The following instructions are a subset of the dotnetapp sample instruction, assuming that you are starting from the root of the dotnet-docker repo.
cd samples
cd dotnetapp
docker build --pull -t dotnetapp .You can test the image with the following instructions.
docker run --rm dotnetappThe following example demonstrates how to create a private ACR Registry. Once an image is in ACR, it is easy to deploy it to ACI.
Note
The instructions use example values that need to be changed to for your environment, specifically the password location, and the user account. More simply, make sure to change "rich" and "richlander" to something else.
az login
az group create --name richlander-containers --location westus
az acr create --name richlander --resource-group richlander-containers --sku BasicNow tag the image to push to your ACR registry. You can also build the image with the right name initially.
docker tag dotnetapp richlander.azurecr.io/dotnetappYou need to login to ACR with docker login to push images. ACR registries are private, so pull, push, and any other registry operation requires login.
To interfact with your credentials, you need to first request to make admin calls to your account with the following command:
az acr update -n richlander --admin-enabled trueYou can see your credentials using the following command.
az acr credential show -n richlanderThere are a few ways to login with these credentials, some of which are demonstrated in the following examples.
The easiest approach is to get the credentials and login in a single command, piping the result of the az acr credential command to docker login via stdin. This approach works on Windows, macOS, and Linux.
az acr credential show -n richlander --query passwords[0].value --output tsv | docker login richlander.azurecr.io -u richlander --password-stdinAlternatively, you can persist your password across logins with the following technique. Make sure to save to a location not managed by source control (to avoid accidental disclosure).
Login on Windows:
az acr credential show -n richlander --query passwords[0].value --output tsv > $env:USERPROFILE\password-acr.txt
type $env:USERPROFILE\password-acr.txt | docker login richlander.azurecr.io -u richlander --password-stdinLogin on macOS or Linux:
az acr credential show -n richlander --query passwords[0].value --output tsv > ~\password-acr.txt
cat ~\password-acr.txt | docker login richlander.azurecr.io -u richlander --password-stdinNow push the image to your ACR registry.
docker push richlander.azurecr.io/dotnetappFirst, docker login to ACR before you can pull the image from another device, just like was described previously. Alternatively, you can pass your password to docker login as plain text via the --password argument.
Update the path locations, registry, and user names to the ones you are using.
Now pull and run the image (the first command isn't strictly necessary):
docker pull richlander.azurecr.io/dotnetapp
docker run --rm richlander.azurecr.io/dotnetapp