In the following steps, you download an official Nginx image from the public Docker Hub registry, tag it for your private Azure container registry, push it to your registry, and then pull it from the registry.

Prerequisites

Azure container registry - Create a container registry in your Azure subscription. For example, use the Azure portal or the Azure CLI.

Docker CLI - You must also have Docker installed locally. Docker provides packages that easily configure Docker on any [macOS][docker-mac], [Windows][docker-windows], or [Linux][docker-linux] system.

Log in to a registry

There are several ways to authenticate to your private container registry. The recommended method when working in a command line is with the Azure CLI command az acr login. For example, to log in to a registry named myregistry:

az acr login --name myregistry

You can also log in with docker login. For example, you might have assigned a service principal to your registry for an automation scenario. When you run the following command, interactively provide the service principal appID (username) and password when prompted. For best practices to manage login credentials, see the docker login command reference:

docker login myregistry.azurecr.io

Both commands return Login Succeeded once completed.

Tip

Always specify the fully qualified registry name (all lowercase) when you use docker login and when you tag images for pushing to your registry. In the examples in this article, the fully qualified name is myregistry.azurecr.io.

Pull the official Nginx image

First, pull the public Nginx image to your local computer.

docker pull nginx

Run the container locally

Execute following docker run command to start a local instance of the Nginx container interactively (-it) on port 8080. The --rm argument specifies that the container should be removed when you stop it.

docker run -it --rm -p 8080:80 nginx

Browse to http://localhost:8080 to view the default web page served by Nginx in the running container. You should see a page similar to the following:

Because you started the container interactively with -it, you can see the Nginx server's output on the command line after navigating to it in your browser.

To stop and remove the container, press Control+C.

Create an alias of the image

Use docker tag to create an alias of the image with the fully qualified path to your registry. This example specifies the samples namespace to avoid clutter in the root of the registry.

Remove the image (optional)

If you no longer need the Nginx image, you can delete it locally with the docker rmi command.

docker rmi myregistry.azurecr.io/samples/nginx

To remove images from your Azure container registry, you can use the Azure CLI command az acr repository delete. For example, the following command deletes the manifest referenced by the samples/nginx:latest tag, any unique layer data, and all other tags referencing the manifest.