Meet101
Meet101

Reputation: 801

How to use the path with the space in docker file

I want to write a cmd in docker file to copy the file at the destination C:\windows\Program Files. I am having an issue due to space in program files. I am able to copy the file to different location. Any suggestion will be appreciated.

I am getting below error:

Step 4 : COPY "C:\docker\prerequisites\MicrosoftSDKs" "C:\Program Files (x86)\MicrosoftSDKs"

Forbidden path outside the build context: C:\docker\prerequisites\MicrosoftSDKs ()

Upvotes: 20

Views: 24605

Answers (4)

hani
hani

Reputation: 51

You can use ARG:

ARG sourc = "C:\docker\prerequisites\MicrosoftSDKs"
ARG destination = "C:\Program Files (x86)\MicrosoftSDKs"
COPY ${sourc} ${destination}

Upvotes: 1

Rivka Altshuler
Rivka Altshuler

Reputation: 1

workaround: write the script with the spaces into a file, and in the docker file, run the script by calling the file.

in a file named myscript.bat write COPY "C:\docker\prerequisites\MicrosoftSDKs" "C:\Program Files (x86)\MicrosoftSDKs"

and in the DockerFile

RUN myscript.bat

Upvotes: -1

VictorV
VictorV

Reputation: 1059

Use the JSON form, you have to use double backslashes inside the braces

FROM microsoft/windowsservercore 
COPY ["C:\\docker\\prerequisites\\MicrosoftSDKs", "C:\\Program Files (x86)\\MicrosoftSDKs"]

You can also use slash:

COPY ["C:/Program Files/nodejs", "/windows/system32"]

Upvotes: 30

SurvivalMachine
SurvivalMachine

Reputation: 8356

Enclosing the path in quotes like this should help if there are spaces:

"C:\windows\Program Files"

Upvotes: -4

Related Questions