colima: PHP code has problem reading files from host-mounted volume

PHP code running inside a container in some cases fails to access files from outside the container.

This is a local development setup with a volume mounted to the php container from outside (ie. it is shared between the container and host).

Steps to reproduce

Save the following as test.php:

<?php
$dir = new RecursiveDirectoryIterator(__DIR__);
$iterator = new RecursiveIteratorIterator($dir);
$iterator->setMaxDepth(0);
$files = iterator_to_array($iterator);
echo "Number of files: ".count($files).PHP_EOL;

Running php test.php outside Docker correctly prints out the number of files in the directory: e.g. Number of files: 12 Running it inside a container (ie. with docker exec) prints out Number of files: 0

Here is a one-liner to test it with (after creating test.php)

docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.4-cli php test.php

(Should never print Number of files: 0 because the directory contains at least the test.php file itself)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 23 (6 by maintainers)

Commits related to this issue

Most upvoted comments

In lima 0.8.2 everything works fine 🎉

CleanShot 2022-02-01 at 10 24 37@2x

I strongly suggest to give mutagen a try for PHP projects. (We use it with ddev, which recently added colima support in dev version. Thanks for this project!)

Is there any place I can find some documentation on how to setup mutagen with colima?

Would it make sense for colima to officially support mutagen and make is easy to setup?