0

Why would Docker be unable to find a file on the host filesystem, when it definitely exists?

I have these lines in my Dockerfile that make a directory in the image and copy a file into it from the host:

RUN mkdir -p /root/somedir
COPY /var/lib/www-data/somedir/somefile /root/somedir/

If I run ls /var/lib/www-data/somedir/somefile on the host, I see the file definitely exists, with permissions that allow anyone to access it.

However, when I try to build my image, Docker fails with the error:

Service 'app_test' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder102437525/var/lib/www-data/somedir/somefile: no such file or directory

I'm building using docker-compose, and my compose file is simply:

version: "3.6"
services:
  app_test:
    build:
      context: ..
      dockerfile: test/Dockerfile
    volumes:
      - /dev/shm:/dev/shm

Why is Docker trying to copy from some temp directory under /var/lib/docker, and why can't it find my file?

Cerin
  • 55,951
  • 85
  • 291
  • 487
  • 1
    Docker can only `COPY` (or `ADD`) files from the `context:` directory and its descendants. Even if you have something that looks like an absolute path, it's interpreted as relative to that directory. – David Maze Jun 27 '21 at 17:48

0 Answers0