Docker Community Forums

Share and learn in the Docker community.

Windows 10 1809: COPY failed

Trying simple Dockerfile

FROM alpine
COPY . /var/www/test

Build it

docker build .

Got

COPY failed: stat /var/lib/docker/tmp/docker-builder431925998/var/www/test: no such file or directory

I belive this is some Docker for Windows issue.


Fresh installed
Windows 10 x64 build 1809

Docker Desktop for Windows
Version 2.0.0.3 (31259)
Channel: stable
Build: 8858db3

Docker Engine
18.09.2

UPD
Diagnostic ID
0E7BDC69-856C-41EC-A67A-D8605B9453EE/20190310133710

Did you check if Docker is able to mount the Windows folders? Try something simple like

docker container run --rm -v "$(pwd):/data" alpine ls /data

This should show you the listing of your current folder.

I’m on windows, there is no pwd command here :frowning:

C:\temp\docker_test>docker container run --rm -v "$(pwd):/data" alpine ls /data
C:\Program Files\Docker\Docker\Resources\bin\docker.EXE: Error response from daemon: create $(pwd): "$(pwd)" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If u intended to pass a host directory, use absolute path.
See 'C:\Program Files\Docker\Docker\Resources\bin\docker.EXE run --help'.

C:\temp\docker_test>docker container run --rm -v "c:\temp\docker_test:/data" alpine ls /data
Dockerfile
test1.txt
test2.txt
test3.txt

The latter attempt with passing current dir explicitly worked fine.

Okay, another one:

PS E:\> docker container run --rm alpine ls /var/www/test
ls: /var/www/test: No such file or directory

Quite obvious, you have to create /var/www/test first.
Now another questions: Seems you create a webserver. Why dont you start from the httpd image?

The same output

C:\temp\docker_test>docker container run --rm alpine ls /var/www/test
ls: /var/www/test: No such file or directory

Now another questions: Seems you create a webserver.

I try to run YII project and started with yiisoftware/yii2-php:5.6-fpm-17.12.0 image but run into COPY issue. Thought it was the image issue, tried alpine image, but it didnt help.

Yes, because you didn’t create the directory. Let’s try directly in Alpine:

PS E:\> docker container run --rm -it alpine
/ # ls /var/www
ls: /var/www: No such file or directory
/ # mkdir -p /var/www/test
/ # ls /var/www
test

Everything is fine

C:\temp\docker_test>docker container run --rm -it alpine
/ # ls /var/www
ls: /var/www: No such file or directory
/ # mkdir -p /var/www/test
/ # ls /var/www
test

Now you can figure out the rest, can’t you?

No, i still don’t understand how to fix the COPY issue.

FROM alpine
RUN mkdir -p /var/www/test
COPY . /var/www/test/

Now you understand.

I’ve found!

COPY works even without RUN mkdir before, as it should. The issue was because i had comment at the end of copy row in my original Dockfile! Haven’t mentioned it because even couldn’t think it could matter.

Works:

FROM alpine
COPY . /var/www/test/

Doesn’t work:

FROM alpine
COPY . /var/www/test/  # TODO change path in PROD
Sending build context to Docker daemon   5.12kB
Step 1/2 : FROM alpine
 ---> 5cb3aa00f899
Step 2/2 : COPY . /var/www/test/  # TODO change path in PROD
COPY failed: stat /var/lib/docker/tmp/docker-builder329756868/var/www/test: no such file or directory

Is this bug or feature?

1 Like

Docker treats lines that begin with # as a comment, unless the line is a valid parser directive. A # marker anywhere else in a line is treated as an argument.

Seems feature.