composer / docker

Composer in Docker
https://hub.docker.com/_/composer/
MIT License
274 stars 133 forks source link

composer.json file exists in current directory but composer is unable to find it (Windows 10) #114

Open jarri-abidi opened 4 years ago

jarri-abidi commented 4 years ago

command being run:

docker run --rm --interactive \
--volume $PWD:/app \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--volume ${COMPOSER_HOME:-$HOME/.composer}:/tmp \
--user $(id -u):$(id -g) \
composer:1.8 install $@

output:

Composer could not find a composer.json file in /app
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section

ls output:

composer.json   composer.lock  
exussum12 commented 4 years ago

what does echo $PWD show ?

Also not sure why you need the $@ there as there are no arguments to pass (I assume the snippet above is from a script and not being ran directly ?

jarri-abidi commented 4 years ago

$PWD is set. image

And yes it's from a script but this is all that is inside the script.

xemuj commented 4 years ago

test changing $PWD to "D:\Projects\server-docker"

phpguru commented 3 years ago

Getting Docker working well under Windows 10 is a challenge. If you are using Docker under WSL2 then your files should be inside of the WSL environment; e.g. /home/<USER>/projects/* and accessed under Windows via \\wsl$\<DISTRO>.

Using this setup, which is the recommended way to do things under WSL2 for maximum performance, the below is what I am getting on Windows 10, WSL2 Ubuntu 20.

This:

alias composer="docker run -it --rm -u $UID -v ${pwd}:/app composer"

did not work; I get:

me@laptop ~/projects/sites/website (master)$ composer install
Composer could not find a composer.json file in /app
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section

This:

alias composer="docker run -it --rm -u $UID -v `pwd`:/app composer"

works for me, but only if you source ~/bashrc while inside the project root:

Your lock file does not contain a compatible set of packages. Please run composer update.

  Problem 1
    - Root composer.json requires php ^7.2.5 but your php version (8.0.2) does not satisfy that requirement.

That got me thinking, this is the only way I could get it to work from any directory:

function composer()
{
   DIR=`pwd`
   docker run -it --rm -u $UID -v $DIR:/app composer $1 $2
}

This may offer future readers some assistance using the Dockerized composer image under WSL2, but I am still not able to use it for projects < php 8.0.2. See https://github.com/phpguru/docker-php-composer/tree/php7.4

alcohol commented 3 years ago

Personally I use the following alias for composer: https://github.com/alcohol/dotfiles/blob/main/bin/composer

In regards to PHP versions, please see our documentation: https://github.com/docker-library/docs/tree/master/composer#php-version--extensions

alcohol commented 3 years ago

Didn't mean to close this.

enfoqueNativo commented 3 years ago

I have the same problem running it as a Gitlab-CI job via docker-dind, $PWD points to the right directory and ls -l shows the correct content.

I'm using this yml file, seems ok to me but gitlab-runner keeps saying there's no composer.json.

Can't provide access to the gitlab-runner, is in a place where only god knows how to reach from outside... and i doubt the IT guys would allow me to share.

thasmo commented 2 years ago

@phpguru

alias composer="docker run -it --rm -u $UID -v ${pwd}:/app composer"

Try using single quotes.