0
votes

Here is the scenario. I have a PHP Docker with the Composer installed, then I tried to use composer package from other repositories and do a composer update. I got the following error:

Cannot create cache directory /root/.composer/cache/repo/https---packagist.org/, or directory is not writable. Proceeding without cache

I know something wrong with /root/.composer directory. I tried to change the permission and delete it, but I couldn't:

Here is the screenshot

Basically, I cannot do anything with "/root/.composer". How can I change permission or delete this folder?

1
You are running Composer as root in the container?Sven
There is only one user in PHP Docker image. So, it doesn't matter you use root or non-root user. Anyway, thanks for asking. I've already found the root cause of this problem. :)Hope

1 Answers

0
votes

I found a solution myself. The problem is the way to install Composer.

This sequence will cause an ERROR above:

  1. Dockerfile

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" RUN php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" RUN php composer-setup.php --filename=composer RUN php -r "unlink('composer-setup.php');" RUN mv composer.phar /usr/local/bin/composer

  1. Run docker-compose

docker-compose up -d

Solution:

  1. Dockerfile

DO NOT install Composer from Dockerfile

  1. Run docker-compose

docker-compose up -d

  1. Inside the container - install composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php --filename=composer php -r "unlink('composer-setup.php');" mv composer.phar /usr/local/bin/composer