Sự kiện
21 giờ 17 thg 3 - 10 giờ 21 thg 3
Tham gia chuỗi buổi gặp gỡ để xây dựng các giải pháp AI có thể mở rộng dựa trên các trường hợp sử dụng trong thế giới thực với các nhà phát triển và chuyên gia đồng nghiệp.
Đăng ký ngayTrình duyệt này không còn được hỗ trợ nữa.
Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.
Azure DevOps Services
This quickstart shows how to build a container image for app deployment using Azure Pipelines. To build this image, all you need is a Dockerfile in your repository. You can build Linux or Windows containers, based on the agent that you use in your pipeline.
In your browser, go the following sample repository and fork it to your GitHub account.
https://github.com/MicrosoftDocs/pipelines-javascript-docker
Sign in to your Azure DevOps organization, and go to your project.
Go to Pipelines, and select New Pipeline or Create Pipeline if creating the first pipeline in the project.
Select GitHub as the location for your source code.
Select your repository, and then select Starter pipeline.
Replace the contents of azure-pipelines.yml with the following code. Based on whether you're deploying a Linux or Windows app, make sure to respectively set vmImage
to either ubuntu-latest
or windows-latest
.
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
imageName: 'pipelines-javascript-docker'
steps:
- task: Docker@2
displayName: Build an image
inputs:
repository: $(imageName)
command: build
Dockerfile: app/Dockerfile
When you're done, select Save and run.
When you add the azure-pipelines.yml file to your repository, you're prompted to add a commit message. Enter a message, and then select Save and run.
When using self-hosted agents, be sure that Docker is installed on the agent's host, and the Docker engine/daemon is running with elevated privileges.
To build the image, Docker must be installed on the agent's host and the Docker engine/daemon must be running with elevated privileges. Use the following steps to create your pipeline using the YAML pipeline editor.
# Docker
# Build a Docker image
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- main
pool:
name: default
demands: docker
variables:
imageName: 'pipelines-javascript-docker'
steps:
- task: Docker@2
displayName: Build an image
inputs:
repository: $(imageName)
command: build
Dockerfile: '$(Build.SourcesDirectory)/app/Dockerfile'
For more information about building Docker images, see the Docker task used by this sample application. You can also directly invoke Docker commands using a command line task.
The container images are built and stored on the agent. You can push your image to Google Container Registry, Docker Hub, or Azure Container Registry. For more information, see Push an image to Docker Hub or Google Container Registry or Push an image to Azure Container Registry.
If you don't plan to continue using this application, delete your pipeline and code repository.
You can build Linux container images using Microsoft-hosted Ubuntu agents or Linux platform-based self-hosted agents.
You can build Windows container images using Microsoft-hosted Windows agents or Windows platform based self-hosted agents. All Microsoft-hosted Windows platform-based agents are shipped with the Moby engine and client needed for Docker builds.
You currently can't use Microsoft-hosted macOS agents to build container images because the Moby engine needed for building the images isn't preinstalled on these agents.
For more information, see the Windows and Linux agent options available with Microsoft-hosted agents.
To avoid spending long intervals pulling Docker images for every job from the container registry, some commonly used images are precached on Microsoft-hosted agents.
BuildKit introduces build improvements around performance, storage management, feature functionality, and security. BuildKit currently isn't supported on Windows hosts.
To enable Docker builds using BuildKit, set the DOCKER_BUILDKIT variable.
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
imageName: 'pipelines-javascript-docker'
DOCKER_BUILDKIT: 1
steps:
- task: Docker@2
displayName: Build an image
inputs:
repository: $(imageName)
command: build
Dockerfile: app/Dockerfile
Docker must be installed and the engine/daemon running on the agent's host. If Docker isn't installed on the agent's host, you can add the Docker installer task to your pipeline. You must add the Docker Installer Task before the Docker Task.
You can use the build
command or any other Docker command.
docker build -f Dockerfile -t foobar.azurecr.io/hello:world .
This command creates an image equivalent to one built with the Docker task. Internally, the Docker task calls the Docker binary on a script and stitches together a few more commands to provide a few more benefits. Learn more about Docker task.
If you're using Microsoft-hosted agents, every job is dispatched to a newly provisioned virtual machine, based on the image generated from azure-pipelines-image-generation repository templates. These virtual machines are cleaned up after the job completes. This ephemeral lifespan prevents reusing these virtual machines for subsequent jobs and the reuse of cached Docker layers. As a workaround, you can set up a multi-stage build that produces two images and pushes them to an image registry at an early stage. You can then tell Docker to use these images as a cache source with the --cache-from
argument.
If you're using self-hosted agents, you can cache Docker layers without any workarounds because the ephemeral lifespan problem doesn't apply to these agents.
When you use Microsoft-hosted Linux agents, you create Linux container images for the x64 architecture. To create images for other architectures, such as x86 or ARM processor, you can use a machine emulator such as QEMU.
The following steps show how to create an ARM processor container image by using QEMU:
Author your Dockerfile with a base image that matches the target architecture:
FROM arm64v8/alpine:latest
Run the following script in your job before you build the image:
# register QEMU binary - this can be done by running the following image
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
# build your image
For more information, see qemu-user-static on GitHub.
For different options on testing containerized applications and publishing the resulting test results, see Publish Test Results task.
After you build your container image, push the image to Azure Container Registry, Docker Hub, or Google Container registry. To learn how to push an image to a container registry, continue to either of the following articles:
Sự kiện
21 giờ 17 thg 3 - 10 giờ 21 thg 3
Tham gia chuỗi buổi gặp gỡ để xây dựng các giải pháp AI có thể mở rộng dựa trên các trường hợp sử dụng trong thế giới thực với các nhà phát triển và chuyên gia đồng nghiệp.
Đăng ký ngayĐào tạo
Mô-đun
Tự động triển khai bộ chứa Docker với Azure Pipelines - Training
Sử dụng Azure Pipelines để triển khai các bộ chứa Docker vào Azure App Service.
Chứng chỉ
Chứng chỉ của Microsoft: Chuyên gia Kỹ sư DevOps - Certifications
Chứng chỉ này đo lường khả năng của bạn để hoàn thành các nhiệm vụ kỹ thuật sau: Thiết kế và thực hiện các quy trình và thông tin liên lạc, thiết kế và thực hiện một chiến lược kiểm soát nguồn, thiết kế và thực hiện quy trình xây dựng và phát hành, phát triển một kế hoạch bảo mật và tuân thủ, và thực hiện một chiến lược thiết bị.