In Windows 10 (cmd) I'm trying to copy a file from a subfolder containing a space character in its name.
First I tried to use quotation marks:
FROM jfloff/alpine-python:2.7
COPY "Folder 1/File.txt" "Dir 1"
Error message:
failed to process "\"Folder": unexpected end of statement while looking for matching double-quote
"JSON" format (skipped the first line):
COPY ["Folder 1/File.txt" "Dir 1"]
Error message:
failed to process "[\"Folder": unexpected end of statement while looking for matching double-quote
Trying to escape with a single backslash:
COPY "Folder\ 1/File.txt" "Dir\ 1"
Error message:
failed to process "\"Folder\\": unexpected end of statement while looking for matching double-quote
Trying to escape with a double backslash:
COPY "Folder\\ 1/File.txt" "Dir\\ 1"
Error message:
failed to process "\"Folder\\\\": unexpected end of statement while looking for matching double-quote
Also tried a suggestion to use %20 instead of space:
COPY ["Folder%201/File.txt" "Dir%201"]
Error message:
COPY failed: no source File
Escape character replacement:
# escape=`
COPY "Folder` 1/File.txt" "Dir 1"
Error message:
failed to process "\"Folder`": unexpected end of statement while looking for matching double-quote
The same, but without quotes:
#escape=`
COPY Folder` 1/File.txt Dir` 1
Error message:
COPY failed: stat /var/lib/docker/tmp/docker-builder082039614/Folder: no such file or directory
Method with packing / unpacking using a tar archive (I'm not happy with that idea).
It should be possible, shouldn't it?
Each RUN command in a Dockerfile creates a new layer to the Docker image. In general, each layer should try to do one job and the fewer layers in an image the easier it is compress. This is why you see all these '&& 's in the RUN command, so that all the shell commands will take place in a single layer.
The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.
COPY is a docker file command that copies files from a local source location to a destination in the Docker container. ADD command is used to copy files/directories into a Docker image. It only has only one assigned function. It can also copy files from a URL.
Docker ADD Command The command copies files/directories to a file system of the specified container. The basic syntax for the ADD command is: ADD <src> … < dest> It includes the source you want to copy ( <src> ) followed by the destination where you want to store it ( <dest> ).
Maybe you can use ARG
to help you, like this:
Dockerfile:
FROM jfloff/alpine-python:2.7
ARG src="Folder 1/File.txt"
ARG target="Dir 1/"
COPY ${src} ${target}
BTW, a /
has to be add at the end of Dir 1
if you treat really want to treat it as a folder.
And, JSON format is also ok, just you miss ,
, it should be:
FROM jfloff/alpine-python:2.7
COPY ["Folder 1/File.txt", "Dir 1/"]
Update for your comments:
In official guide, it said:
When copying files or directories that contain special characters (such as [ and ]), you need to escape those paths following the Golang rules to prevent them from being treated as a matching pattern.
So, for your case, it should be:
FROM jfloff/alpine-python:2.7
ARG src="[[]Folder 1]/__SLIM_TEMPLATE.mm"
ARG target="[Folder 1]/"
COPY ${src} ${target}
Or:
FROM jfloff/alpine-python:2.7
COPY ["[[]Folder 1]/__SLIM_TEMPLATE.mm", "[Folder 1]/"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With