Docker Build Copy Directory Not Found
Wednesday, December 10, 2025
So, I tried to provide parameter to Dockerfile since my CI/CD pipeline runs in Azure DevOps and the artifact staging directory is provided as variable and I don't want to hard code the value inside Dockerfile.
Enter Build variables https://docs.docker.com/build/building/variables/. It seems simple. All I need in my dockerfile is:
FROM ...
ARG SRC="./app"
COPY ${SRC} .
Then I can pass the value:
docker build --build-arg SRC=$(Build.ArtifactStagingDirectory) .
Well, it throws an error:
ERROR: failed to build: failed to solve: failed to compute cache key: failed to calculate checksum of ref 4ce6fa60-2f23-4ac2-b56a-0440c85af90a::qzmaj2vppe2uy3akiebhn7od1: "/home/vsts/work/1/a": not found
The path is correct, but somehow Docker can't find the directory. Apparently, it has something to do with build context https://docs.docker.com/build/concepts/context/ because the following works:
cd $(Build.ArtifactStagingDirectory)
docker build --build-arg SRC=. .
Which means only the directory on which the Dockerfile is being executed from and its subdirectories are accessible inside Dockerfile.