Dev environments

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

To initialize a project, please create a composer.json file. See https://getcomposer.org/basic-usage

ERROR: 1

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.

Can anyone help me with my problem?|

This is my docker-compose file:

https://pastebin.com/gitPPEkf

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).

Do you mean the dev environment that you can start from the GUI of Docker Desktop and open the code in VSCode?

  • Does that composer.json exist in your dev environment?
  • How did you copy the sourcecode into the dev container? From git repo or from the host machine?
  • Where do you run docker-compose? From VSCode?
  • How did you installed docker-compose in the dev enviroment?

Whan can you find when you run these two commands:

ls -la

and

sudo docker-compose run --rm --entrypoint "" composer ls -la

PS:: Please use the </> button to insert code and error messages so your post can be more readable.