Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jarri-abidi opened this issue Jul 30, 2020 · 8 comments
Labels

Comments

@jarri-abidi
Copy link

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  
@jarri-abidi jarri-abidi changed the title composer.json file exists in current directory but composer is unable to find it composer.json file exists in current directory but composer is unable to find it (Windows 10) Jul 30, 2020
@exussum12
Copy link
Contributor

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
Copy link
Author

$PWD is set.
image

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

@xemuj
Copy link

xemuj commented Nov 5, 2020

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

@phpguru
Copy link

phpguru commented Feb 20, 2021

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
Copy link
Member

alcohol commented Feb 21, 2021

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 alcohol closed this as completed Feb 21, 2021
@alcohol alcohol reopened this Feb 21, 2021
@alcohol
Copy link
Member

alcohol commented Feb 21, 2021

Didn't mean to close this.

@enfoqueNativo
Copy link

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
Copy link

thasmo commented Jun 28, 2022

@phpguru

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

Try using single quotes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants