Search code examples
phpdockerapacheweasyprint

"no such file or directory" when passing full path to Docker image, but works with relative path to same folder


From a PHP page in Apache I'm trying to run a docker command that will generate a PDF. I've added both my user and the www-data user to the docker group so they can execute a docker command without sudo.

This works within a PHP file that exists at the /home/my_user/projects/my_project/public folder:

system("docker run --rm -v `pwd`:/app -w /app weasyprint:51 ./healthcheck.htm /weasyprint_test.pdf");

But when I specify the full path (which I've verified is correct), it doesn't work:

system("docker run --rm -v `pwd`:/app -w /app weasyprint:51 /home/my_user/projects/my_project/public/healthcheck.htm /home/my_user/projects/my_project/public/weasyprint_test.pdf");

I see this in the PHP error log when I run the second version: su-exec: /home/my_user/projects/my_project/public/healthcheck.htm: No such file or directory

For the life of me, I can't figure out why the first version would work and the second wouldn't because they are referring to the same path, just via different syntax. Please let me know if you have any ideas.

If it helps, I'm using the this Docker image for Weasyprint: https://hub.docker.com/r/minidocks/weasyprint


Solution

  • On the Docker VM run ls /home/ and I would wager the directory you expect isn't there. The user referenced in your path probably doesn't exist on the VM, only on your host machine.

    The relative path works because it's relative to the root directory provided.