고급 컨테이너 예제

컨테이너에 빌드 도구 설치에서 샘플 Dockerfile은 항상 최신 microsoft/windowsservercore 이미지와 최신 Visual Studio Build Tools 설치 관리자를 기반으로 하는 microsoft/dotnet-framework:4.8 이미지를 사용합니다. 이 이미지를 다른 사용자가 풀할 수 있는 Docker 레지스트리에 게시할 경우 많은 시나리오에 괜찮을 수 있습니다. 그러나 실제로 사용하는 기본 이미지, 다운로드하는 바이너리, 그리고 설치하는 도구 버전에 대해 더 구체적인 것이 일반적입니다.

다음 예제의 Dockerfile은 microsoft/dotnet-framework 이미지의 특정 버전 태그를 사용합니다. 기본 이미지에 특정 태그를 사용하는 것이 일반적이며 이미지를 빌드 또는 다시 빌드할 때 항상 동일한 근거가 있다는 점을 기억하는 것이 쉽습니다.

참고 항목

컨테이너에서 설치 관리자 실행 시 알려진 문제가 있는 microsoft/windowsservercore:10.0.14393.1593 또는 이를 기반으로 하는 이미지에는 Visual Studio를 설치할 수 없습니다. 자세한 내용은 컨테이너의 알려진 문제를 참조하세요.

다음 예제에서는 최신 릴리스의 Build Tools를 다운로드합니다. 나중에 컨테이너에 설치할 수 있는 이전 버전의 Build Tools를 사용하려면 먼저 레이아웃을 만들고유지해야 합니다.

스크립트 설치

설치 오류가 발생할 때 로그를 수집하려면 다음 콘텐츠를 포함하는 작업 디렉터리에서 "Install.cmd"라는 일괄 처리 스크립트를 만듭니다.

@if not defined _echo echo off
setlocal enabledelayedexpansion

call %*
if "%ERRORLEVEL%"=="3010" (
    exit /b 0
) else (
    if not "%ERRORLEVEL%"=="0" (
        set ERR=%ERRORLEVEL%
        call C:\TEMP\collect.exe -zip:C:\vslogs.zip

        exit /b !ERR!
    )
)

exit /b 0

Dockerfile

작업 디렉터리에서 다음 콘텐츠로 "Dockerfile"을 만듭니다.

# escape=`

# Use a specific tagged image. Tags can be changed, though that is unlikely for most images.
# You could also use the immutable tag @sha256:324e9ab7262331ebb16a4100d0fb1cfb804395a766e3bb1806c62989d1fc1326
ARG FROM_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2019
FROM ${FROM_IMAGE}

# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]

# Copy our Install script.
COPY Install.cmd C:\TEMP\

# Download collect.exe in case of an install failure.
ADD https://aka.ms/vscollect.exe C:\TEMP\collect.exe

# Use the latest release channel. For more control, specify the location of an internal layout.
ARG CHANNEL_URL=https://aka.ms/vs/16/release/channel
ADD ${CHANNEL_URL} C:\TEMP\VisualStudio.chman

RUN `
    # Download the Build Tools bootstrapper.
    curl -SL --output vs_buildtools.exe https://aka.ms/vs/16/release/vs_buildtools.exe `
    `
    # Install Build Tools with the Microsoft.VisualStudio.Workload.AzureBuildTools workload, excluding workloads and components with known issues.
    && (call C:\TEMP\Install.cmd vs_buildtools.exe --quiet --wait --norestart --nocache install `
        --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools" `
        --channelUri C:\TEMP\VisualStudio.chman `
        --installChannelUri C:\TEMP\VisualStudio.chman `
        --add Microsoft.VisualStudio.Workload.AzureBuildTools `
        --remove Microsoft.VisualStudio.Component.Windows10SDK.10240 `
        --remove Microsoft.VisualStudio.Component.Windows10SDK.10586 `
        --remove Microsoft.VisualStudio.Component.Windows10SDK.14393 `
        --remove Microsoft.VisualStudio.Component.Windows81SDK) `
    `
    # Cleanup
    && del /q vs_buildtools.exe

# Define the entry point for the Docker container.
# This entry point starts the developer command prompt and launches the PowerShell shell.
ENTRYPOINT ["C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
# escape=`

# Use the latest Windows Server Core 2019 image.
ARG FROM_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2019
FROM ${FROM_IMAGE}

# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]

# Copy our Install script.
COPY Install.cmd C:\TEMP\

# Download collect.exe in case of an install failure.
ADD https://aka.ms/vscollect.exe C:\TEMP\collect.exe

# Use the latest release channel. For more control, specify the location of an internal layout.
ARG CHANNEL_URL=https://aka.ms/vs/17/release/channel
ADD ${CHANNEL_URL} C:\TEMP\VisualStudio.chman

RUN `
    # Download the Build Tools bootstrapper.
    curl -SL --output vs_buildtools.exe https://aka.ms/vs/17/release/vs_buildtools.exe `
    `
    # Install Build Tools with the Microsoft.VisualStudio.Workload.AzureBuildTools workload, excluding workloads and components with known issues.
    && (call C:\TEMP\Install.cmd vs_buildtools.exe --quiet --wait --norestart --nocache install `
        --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" `
        --channelUri C:\TEMP\VisualStudio.chman `
        --installChannelUri C:\TEMP\VisualStudio.chman `
        --add Microsoft.VisualStudio.Workload.AzureBuildTools `
        --remove Microsoft.VisualStudio.Component.Windows10SDK.10240 `
        --remove Microsoft.VisualStudio.Component.Windows10SDK.10586 `
        --remove Microsoft.VisualStudio.Component.Windows10SDK.14393 `
        --remove Microsoft.VisualStudio.Component.Windows81SDK) `
    `
    # Cleanup
    && del /q vs_buildtools.exe

# Define the entry point for the Docker container.
# This entry point starts the developer command prompt and launches the PowerShell shell.
ENTRYPOINT ["C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

다음 명령을 실행하여 현재 작업 디렉터리에 이미지를 빌드합니다.

docker build -t buildtools2019:16.0.28714.193 -t buildtools2019:latest -m 2GB .
docker build -t buildtools2022:17.0 -t buildtools2022:latest -m 2GB .

필요에 따라 --build-arg 명령줄 스위치를 사용하여 FROM_IMAGE 또는 CHANNEL_URL 인수 중 하나 또는 모두를 전달하여 고정된 이미지를 유지하도록 다른 기본 이미지 또는 내부 레이아웃의 위치를 지정합니다.

워크로드 및 구성 요소 목록은 Visual Studio Build Tools 구성 요소 디렉터리를 참조하세요.

설치 오류 진단

이 예제에서는 특정 도구를 다운로드하고 해시가 일치하는지 검증합니다. 또한 설치 실패가 발생할 경우 호스트 시스템으로 로그를 복사하여 실패를 분석할 수 있도록 최신 Visual Studio 및 .NET 로컬 컬렉션을 다운로드합니다.

> docker build -t buildtools2019:16.0.28714.193 -t buildtools2019:latest -m 2GB .
Sending build context to Docker daemon

...
Step 8/10 : RUN C:\TEMP\Install.cmd C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache ...
 ---> Running in 4b62b4ce3a3c
The command 'cmd /S /C C:\TEMP\Install.cmd C:\TEMP\vs_buildtools.exe ...' returned a non-zero code: 1603

> docker cp 4b62b4ce3a3c:C:\vslogs.zip "%TEMP%\vslogs.zip"
> docker build -t buildtools2022:17.0 -t buildtools2022:latest -m 2GB .
Sending build context to Docker daemon

...
Step 8/10 : RUN C:\TEMP\Install.cmd C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache ...
 ---> Running in 4b62b4ce3a3c
The command 'cmd /S /C C:\TEMP\Install.cmd C:\TEMP\vs_buildtools.exe ...' returned a non-zero code: 1603

> docker cp 4b62b4ce3a3c:C:\vslogs.zip "%TEMP%\vslogs.zip"

마지막 줄의 실행이 끝나면 머신에서 "%TEMP%\vslogs.zip"을 열거나 개발자 커뮤니티 웹 사이트에서 문제를 제출합니다.

지원 또는 문제 해결

때로는 무엇인가 잘못될 수도 있습니다. Visual Studio 설치에 실패하는 경우 단계별 지침은 Visual Studio 설치 및 업그레이드 문제 해결을 참조하세요.

몇 가지 추가 지원 옵션은 다음과 같습니다.

  • 설치 관련 문제를 위한 설치 채팅(영어만 가능) 지원 옵션이 제공됩니다.
  • Visual Studio 설치 관리자와 Visual Studio IDE에 모두 표시되는 문제 보고 도구를 통해 Microsoft에 제품 문제를 보고합니다. IT 관리자이고 Visual Studio가 설치되어 있지 않은 경우 여기에서 IT 관리자 피드백을 제출할 수 있습니다.
  • Visual Studio 개발자 커뮤니티에서 기능을 제안하고, 제품 문제를 추적하고, 답변을 찾습니다.