Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to _directly_ COPY files to "Program Files (x86)" folder in a Windows container?

My question is specific to the Docker for Windows. The version I'm using is 17.03.1-ce-rc1-win3 (10625) on Windows 10 Pro x64.

I'm trying to create an image where I need to copy a folder into the "Program Files (x86)" folder in my container based on microsoft/dotnet-framework:3.5 image.

My Dockerfile is super simple ...

# escape=`

FROM microsoft/dotnet-framework:3.5

COPY ["TestFolder", "C:\Program Files (x86)\TestFolder"]

Running docker build, I ended up

Step 2/2 : COPY ["TestFolder", "C:\Program Files (x86)\TestFolder"]
GetFileAttributesEx C:\Program: The system cannot find the file specified.

It looks like docker mistakenly stopped parsing the dest name at the first whitespace. However this COPY ["<src>", ..."<dest>"] is exactly the syntax for dealing the paths containing whitespace (ref). And if I use any other folder name like "Foo Bar" instead, the COPY instruction just works as expected.

So my current workaround is using WORKDIR first to change the working dir to the "Prog...(x86)" folder and then doing COPY without explicitly giving the full dest path.

But I really would like to know if I did anything wrong with the COPY instruction.

Thanks.

like image 300
W Si Avatar asked Feb 05 '23 19:02

W Si


1 Answers

You have to use double backslashes inside the braces

FROM microsoft/windowsservercore

COPY ["test.txt", "c:\\program files\\WindowsPowerShell\\Modules\\test.txt"]

It is interpreted as JSON.

like image 166
Stefan Scherer Avatar answered Feb 13 '23 02:02

Stefan Scherer