添加或复制文件夹到 windows docker 容器

Add or copy folder to windows docker container

我想将文件夹复制到 windows 容器特定目录。我无法添加它。

我试过了

ADD VC  C:\TEMP\VC

这有效并将我的 VC 文件夹放入 windows 容器文件夹 C:\TEMP\VC

但是当我尝试时:

ADD VC  C:\Program Files (x86)\Microsoft Visual Studio19\buildtools\MSBuild\Microsoft\VC

我收到错误:

Step 4/6 : ADD VC  C:\Program Files (x86)\Microsoft Visual Studio19\buildtools\MSBuild\Microsoft\VC
ADD failed: CreateFile \?\C:\ProgramData\Docker\tmp\docker-builder462071631\Program: The system cannot find the file specified.

我也试过:

ADD VC  "C:\Program Files (x86)\Microsoft Visual Studio19\buildtools\MSBuild\Microsoft\VC"
failed to process "\"C:\Program": unexpected end of statement while looking for matching double-quote

Step 4/6 : ADD VC  C:\Program Files (x86)\Microsoft Visual Studio\2019\buildtools\MSBuild\Microsoft\VC
ADD failed: CreateFile \?\C:\ProgramData\Docker\tmp\docker-builder633588211\Program: The system cannot find the file specified.

没有任何效果。

Dokcerfile

# escape=`

# Use the latest Windows Server Core image with .NET Framework 4.8.
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019

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

# Download the Build Tools bootstrapper.
ADD https://aka.ms/vs/16/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe
ADD VC  C:\TEMP\VC   
#ADD /ConsoleApplication2\Debug\ConsoleApplication2.exe   C:\
# Install Build Tools with the Microsoft.VisualStudio.Workload.AzureBuildTools workload, excluding workloads and components with known issues.
RUN C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache `
    --installPath C:\BuildTools `
    --add Microsoft.Component.MSBuild `
    --add Microsoft.VisualStudio.Component.WinXP`
    --add Microsoft.VisualStudio.Component.VC.14.20.x86.x64 `
    --add Microsoft.VisualStudio.Component.VC.140`
    --add Microsoft.VisualStudio.Component.VC.Redist.MSM`
    --add Microsoft.VisualStudio.Component.VC.14.25.CLI.Support`
    --add Microsoft.VisualStudio.Component.NuGet.BuildTools`
    --add Microsoft.VisualStudio.Component.Roslyn.Compiler`
    -add Microsoft.VisualStudio.ComponentGroup.VisualStudioExtensionBuildTools.Prerequisites`
    -add Microsoft.VisualStudio.Component.VSSDKBuildTools`
    --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended \ `
     --add Microsoft.VisualStudio.Component.Static.Analysis.Tools \`
    --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \`
    --add Microsoft.VisualStudio.Component.VC.CMake.Project \`
    --add Microsoft.VisualStudio.Component.VC.CoreBuildTools \`
    --add Microsoft.VisualStudio.Component.VC.ATLMFC \`
    --add Microsoft.VisualStudio.Component.VC.ATL \`
    --add Microsoft.VisualStudio.Component.Windows10SDK.16299.Desktop \`
    --add Microsoft.VisualStudio.Component.Windows10SDK.16299.UWP \`
    --add Microsoft.VisualStudio.Component.Windows10SDK.16299.UWP.Native \`
    --add Microsoft.VisualStudio.Component.Windows10SDK \`
    --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81 \`
    --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest \`
    --add Microsoft.Component.VC.Runtime.UCRTSDK \`
    --add Microsoft.VisualStudio.Component.WinXP \`
    --add Microsoft.Component.MSBuild `
    --remove Microsoft.VisualStudio.Component.Windows10SDK.10240 `
    --remove Microsoft.VisualStudio.Component.Windows10SDK.10586 `
    --remove Microsoft.VisualStudio.Component.Windows10SDK.14393 `
    --remove Microsoft.VisualStudio.Component.Windows81SDK `
 || IF "%ERRORLEVEL%"=="3010" EXIT 0

# Define the entry point for the docker container.
# This entry point starts the developer command prompt and launches the PowerShell shell.
ENTRYPOINT ["C:\BuildTools\Common7\Tools\VsDevCmd.bat", "&&","powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

给定以下 Dockerfile

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
COPY ["VC", "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/MSBuild/Microsoft/VC"]

构建目录如下

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          16/07/2020    12:34                VC
-a---          16/07/2020    14:36            174 Dockerfile

运行 docker 构建会将构建根目录中的 VC 文件夹的内容复制到目标的 VC 文件夹而不会出错

C:\temp\test> docker build -t testcopy .
Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
 ---> be6035551084
Step 2/2 : COPY ["VC", "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/MSBuild/Microsoft/VC"]
 ---> 7521a3e989ce
Successfully built 7521a3e989ce
Successfully tagged testcopy:latest

如果您随后 运行 创建了容器,您应该会发现文件已正确复制

C:\>dir "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/MSBuild/Microsoft/VC"
 Volume in drive C has no label.
 Volume Serial Number is B40D-C55F

 Directory of C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\MSBuild\Microsoft\VC

07/16/2020  02:37 PM    <DIR>          .
07/16/2020  02:37 PM    <DIR>          ..
07/16/2020  12:26 PM                 0 Test.txt
               1 File(s)              0 bytes
               2 Dir(s)  21,206,806,528 bytes free

如果仍然出现错误,则可能是 docker 安装不当。此测试是 运行,服务器 2019 上的最新 docker 桌面版本,副本工作正常。