Add or copy folder to windows docker container

一世执手 提交于 2020-07-18 21:02:57

问题


I want to copy a folder to a windows container specific directory. I am not able to add it.

I tried

ADD VC  C:\TEMP\VC

This works and put my VC folder into windows container folder C:\TEMP\VC.

But when I try:

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

I get the error:

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-builder462071631\Program: The system cannot find the file specified.

I have also tried:

ADD VC  "C:\Program Files (x86)\Microsoft Visual Studio\2019\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.

Nothing works.

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"]

回答1:


Given the following 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"]

With the build directory as follows

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

Running a docker build will copy the contents of the VC folder in the build root, to the VC folder at the target without error

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

If you then run the created container, you should find the files are correctly copied

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 Studio\2019\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

If you are still getting errors, you may have a dodgy install of docker. This test was run with the lastest docker desktop version on server 2019 and the copy worked fine.




回答2:


Try escaping whitespace in the third attempt you made:

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

Or perhaps try escaping with the ^:

ADD VC  C:\Program^ Files^ (x86)\Microsoft^ Visual^ Studio\2019\buildtools\MSBuild\Microsoft\VC

You could also try using the short path for the path, which avoids any whitespace issues too.



来源:https://stackoverflow.com/questions/62551660/add-or-copy-folder-to-windows-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!