Johannes Riecken
Johannes Riecken

Reputation: 2515

Refer to filename containing newline in Dockerfile

I'm trying to use the COPY command with a directory name containing newlines and I tried to write it with \n, \x0a or with a literal newline, but docker doesn't find the directory with any of these approaches, though it does find it if I rename it to not have a newline character in it. The docker documentation also doesn't seem to mention this. How can I get this to work?

Minimal example:

$ touch $'foo\nbar'
$ echo -e 'FROM busybox\nCOPY "foo\\nbar" /tmp/\nCMD /bin/sh' >|Dockerfile
$ docker build .
Sending build context to Docker daemon  8.192kB
Step 1/3 : FROM busybox
 ---> 020584afccce
Step 2/3 : COPY "foo\nbar" /tmp/
COPY failed: stat /var/lib/docker/tmp/docker-builder128029906/foo\nbar: no such file or directory

Upvotes: 2

Views: 379

Answers (1)

KamilCuk
KamilCuk

Reputation: 141688

The following seems to work:

ADD ["\n.txt", "\n.txt"]

Looks like \r, \b, \n work, but \x** or \e do not. I have Docker version 19.03.5-ce, build 633a0ea838. I can't find any reference on this, so if someone finds it and sees this answer, feel free to edit it.

Upvotes: 3

Related Questions