Use Azure Pipelines to push your image to a container registry such as Azure Container Registry, Docker Hub, or Google Container Registry. Azure Container Registry is a managed registry service based on the open-source Docker Registry 2.0.
You'll use the Docker@2 task to build or push Docker images, login or logout, start or stop containers, or run a Docker command.
The task uses a Docker registry service connection to log in and push to a container registry. The process for creating a Docker registry service connection differs depending on your registry.
The Docker registry service connection stores credentials to the container registry before pushing the image. You can also directly reference service connections in Docker without an additional script task.
Create a Docker service connection
You'll need to follow a different process to create a service connection for Azure Container Registry, Docker Hub, and Google Container Registry.
With the Azure Container Registry option, the subscription (associated with the Azure Active Directory identity of the user signed into Azure DevOps) and container registry within the subscription are used to create the service connection.
When you create a new pipeline for a repository that contains a Dockerfile, Azure Pipelines will detect Dockerfile in the repository. To start this process, create a new pipeline and select the repository with your Dockerfile.
From the Configure tab, select the Docker - Build and push an image to Azure Container Registry task.
Select your Azure Subscription, and then select Continue.
Select your Container registry from the dropdown menu, and then provide an Image Name to your container image.
Select Validate and configure when you are done.
As Azure Pipelines creates your pipeline, it will:
Create a Docker registry service connection to enable your pipeline to push images to your container registry.
Generate an azure-pipelines.yml file, which defines your pipeline.
Choose the Docker Hub option under Docker registry service connection and provide your username and password to create a Docker service connection.
To create a Docker service connection associated with Google Container Registry:
Open your project in the GCP Console and then open Cloud Shell
To save time typing your project ID and Compute Engine zone options, set default configuration values by running the following commands:
gcloud config set project [PROJECT_NAME]
gcloud config set compute/zone [ZONE]
Replace [PROJECT_NAME] with the name of your GCP project and replace [ZONE] with the name of the zone that you're going to use for creating resources. If you're unsure about which zone to pick, use us-central1-a. For example:
gcloud config set project azure-pipelines-test-project-12345
gcloud config set compute/zone us-central1-a
Enable the Container Registry API for your project: