コンテナーの高度な例
「Build Tools をコンテナーにインストールする」のサンプル Dockerfile では、最新の microsoft/windowsservercore イメージに基づく microsoft/dotnet-framework:4.8 イメージと、最新の Visual Studio Build Tools インストーラーが常に使用されます。 他のユーザーがプルできるように、このイメージを Docker レジストリ に発行する場合、このイメージは多くのシナリオで問題ない可能性があります。 ただし、実際には、使用する基本イメージ、ダウンロードするバイナリ、インストールするツールのバージョンについて具体的に指定する方が一般的です。
次の Dockerfile の例では、microsoft/dotnet-framework イメージの特定のバージョン タグを使用します。 基本イメージに特定のタグを使用することは一般的であり、イメージのビルドまたは再構築には常に同じ基礎があることを覚えやすくします。
手記
Visual Studio を microsoft/windowsservercore:10.0.14393.1593 またはそれに基づくイメージ (コンテナーでインストーラーを起動する際の既知の問題) にインストールすることはできません。 詳細については、「コンテナーの既知の問題」を参照してください。
次の例では、ビルド ツールの最新リリースをダウンロードします。 後でコンテナーにインストールできる以前のバージョンの 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 および .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" を開くか、Developer Community Web サイトで問題を送信します。
サポートまたはトラブルシューティング
場合によっては、問題が発生することがあります。 Visual Studio のインストールが失敗した場合は、「Visual Studio のインストールとアップグレードに関する問題のトラブルシューティング」 を参照して、詳細なガイダンスを参照してください。
その他のサポート オプションをいくつか次に示します。
- インストール関連の問題については、インストール チャット (英語のみ) サポート オプションを使用します。
- Visual Studio インストーラーと Visual Studio IDE の両方に表示される 問題の報告 ツールを使用して、製品の問題を報告します。 IT 管理者であり、Visual Studio がインストールされていない場合は、IT 管理者フィードバックを送信できます。
- 機能を提案し、製品の問題を追跡し、Visual Studio Developer Communityで回答を見つけます。