Docker file no such file or directory even when file exists

Currently learning how to work with Docker containers, and ran into this weird error. Turns out there is a simple explanation.

I setup my Dockerfile and included the following line:

ADD /home/gp/git/test/api /var/www/api

However when I ran my build command I got the following error:

INFO[0000] home/gp/git/test/api: no such file or directory

Copy-pasting this after a cd command quickly confirmed the directory definitely exists. So what is going on?

Turns out when Docker runs it can only see files and folders at or below the current directory level (the current directory level being the level the Dockerfile is stored). Because this was off the path of where I was running my build (I was in home/gp/git/test) it could not find it. Changing the command to this worked:

ADD api /var/www/api

Note that you will need to rebuild your images from scratch.

Tags: ,

Leave a Reply