Hi, I am a php Laravel developer, and for my projects I normally use a web server created and setup in docker (nginx, php, composer, mysql, adminer, node, mailhog). Everything works perfectly, now after getting a new laptop I decided to use docker dev environments. But where I have a problem running almost any command. In docker-compose I have /var/www/html set as working_dir, I have the same path set for volumes.
But if i try to run a command, for example:
sudo docker-compose run --rm composer install
I get an error like this:
Composer could not find a composer.json file in /var/www/html
I’ve been struggling with this for the second day, and I haven’t found anything via google. Just to point out that composer.json, I have in the root just like docker-compose.yml.
A relevant detail is missing: how does the composer.json comme to that path?
As part of the image?
As directory content of a named volume?
As directory content of a bind volume?
A volume will always eclipse the container folder with the volume mounted on top of the existing container - therefore the original content (inherited from the image) will become invisible to the container.
In case an empty named volume is used, the content from the container path will be copied to the volume once, before the volume is mounted into the container path (and again eclipses the original content, but now you have a copy from that point in time in your volume). If you modify the image to have changes in that container folder, the named volume will not pick them up and still eclipse the content with whatever state is in the named volume. Relying on copy on first use is rarely a good idea…
Update: your pastbin link shows a compose file, which uses binds for everything except mysql. mysql uses the only named volume. So the composer.json must exist in the folder where you run docker-compose from, as most of your host paths are just . (=current folder).