TrafeX / docker-php-nginx

Docker image with PHP-FPM 8.3 & Nginx 1.26 on Alpine Linux
https://hub.docker.com/r/trafex/php-nginx
MIT License
1.39k stars 739 forks source link

I cannot run commands like "composer install" when using Windows WSL #177

Open maxacarvalho opened 6 months ago

maxacarvalho commented 6 months ago

Hi, I'm facing an issue with the image when running the project on a Windows machine running WSL.

It is a permission issue. Basically, I cannot install the composer dependencies.

Here's the output of the error:

#18 phar:///usr/bin/composer/vendor/symfony/console/Application.php(301): Symfony\Component\Console\Application->doRunCommand()
#19 phar:///usr/bin/composer/src/Composer/Console/Application.php(394): Symfony\Component\Console\Application->doRun()
#20 phar:///usr/bin/composer/vendor/symfony/console/Application.php(171): Composer\Console\Application->doRun()
#21 phar:///usr/bin/composer/src/Composer/Console/Application.php(148): Symfony\Component\Console\Application->run()
#22 phar:///usr/bin/composer/bin/composer(93): Composer\Console\Application->run()
#23 /usr/bin/composer(29): require('...')
#24 {main}
Unhandled promise rejection with RuntimeException: Failed to execute git clone --mirror -- 'https://ghp...ExT:x-oauth-basic@github.com/symfony/translation.git' '/.composer/cache/vcs/https---github.com-symfony-translation.git/'

fatal: could not create leading directories of '/.composer/cache/vcs/https---github.com-symfony-translation.git'
 in phar:///usr/bin/composer/src/Composer/Util/Git.php:473
Stack trace:
#0 phar:///usr/bin/composer/src/Composer/Util/Git.php(259): Composer\Util\Git->throwException()
#1 phar:///usr/bin/composer/src/Composer/Util/Git.php(296): Composer\Util\Git->runCommand()
#2 phar:///usr/bin/composer/src/Composer/Util/Git.php(329): Composer\Util\Git->syncMirror()
#3 phar:///usr/bin/composer/src/Composer/Downloader/GitDownloader.php(78): Composer\Util\Git->fetchRefOrSyncMirror()
#4 phar:///usr/bin/composer/src/Composer/Downloader/VcsDownloader.php(73): Composer\Downloader\GitDownloader->doDownload()
#5 phar:///usr/bin/composer/src/Composer/Downloader/DownloadManager.php(223): Composer\Downloader\VcsDownloader->download()
#6 phar:///usr/bin/composer/src/Composer/Downloader/DownloadManager.php(216): Composer\Downloader\DownloadManager->Composer\Downloader\{closure}()
#7 phar:///usr/bin/composer/vendor/react/promise/src/Internal/RejectedPromise.php(73): Composer\Downloader\DownloadManager::Composer\Downloader\{closure}()
#8 phar:///usr/bin/composer/src/Composer/Downloader/DownloadManager.php(228): React\Promise\Internal\RejectedPromise->then()
#9 phar:///usr/bin/composer/src/Composer/Downloader/DownloadManager.php(235): Composer\Downloader\DownloadManager->Composer\Downloader\{closure}()
#10 phar:///usr/bin/composer/src/Composer/Installer/LibraryInstaller.php(114): Composer\Downloader\DownloadManager->download()
#11 phar:///usr/bin/composer/src/Composer/Installer/InstallationManager.php(277): Composer\Installer\LibraryInstaller->download()
#12 phar:///usr/bin/composer/src/Composer/Installer/InstallationManager.php(218): Composer\Installer\InstallationManager->downloadAndExecuteBatch()
#13 phar:///usr/bin/composer/src/Composer/Installer.php(827): Composer\Installer\InstallationManager->execute()
#14 phar:///usr/bin/composer/src/Composer/Installer.php(300): Composer\Installer->doInstall()
#15 phar:///usr/bin/composer/src/Composer/Command/InstallCommand.php(147): Composer\Installer->run()
#16 phar:///usr/bin/composer/vendor/symfony/console/Command/Command.php(298): Composer\Command\InstallCommand->execute()
#17 phar:///usr/bin/composer/vendor/symfony/console/Application.php(1040): Symfony\Component\Console\Command\Command->run()
#18 phar:///usr/bin/composer/vendor/symfony/console/Application.php(301): Symfony\Component\Console\Application->doRunCommand()
#19 phar:///usr/bin/composer/src/Composer/Console/Application.php(394): Symfony\Component\Console\Application->doRun()
#20 phar:///usr/bin/composer/vendor/symfony/console/Application.php(171): Composer\Console\Application->doRun()
#21 phar:///usr/bin/composer/src/Composer/Console/Application.php(148): Symfony\Component\Console\Application->run()
#22 phar:///usr/bin/composer/bin/composer(93): Composer\Console\Application->run()
#23 /usr/bin/composer(29): require('...')
#24 {main}

In Git.php line 473:

  Failed to execute git clone --mirror -- 'https://ghp...ExT:x-oauth-basic@github.com/symfony/clock.git' '/.composer/cache/vcs/https---github.com-symfony-clock.git/'

  fatal: could not create leading directories of '/.composer/cache/vcs/https---github.com-symfony-clock.git'

install [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--download-only] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-progress] [--no-install] [--audit] [--audit-format AUDIT-FORMAT] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>...]

And here's my Dockerfile

FROM node:21-alpine AS node
FROM trafex/php-nginx:3.5.0

# Temporary switch to root
USER root

# Extensions
RUN apk add --no-cache \
    php83-bcmath \
    php83-fpm \
    php83-iconv \
    php83-mysqlnd \
    php83-pcntl \
    php83-pdo \
    php83-pdo_mysql \
    php83-pdo_sqlite \
    php83-pecl-redis \
    php83-openssl \
    php83-posix \
    php83-simplexml \
    php83-sockets \
    php83-sodium \
    php83-xsl \
    php83-zip

# Install
RUN apk add --no-cache tzdata ca-certificates mysql-client mariadb-connector-c perl curl git patch pv grep php83-pecl-xdebug

# Add configuration
COPY docker/php-nginx/config/conf.d/50_xdebug.ini ${PHP_INI_DIR}/conf.d/50_xdebug.ini

# Install composer from the official image
COPY --from=composer /usr/bin/composer /usr/bin/composer

# Switch back to non-root user
USER nobody

COPY docker/php-nginx/config/conf.d/default.conf /etc/nginx/conf.d/default.conf

# NODE
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=node /usr/local/bin/node /usr/local/bin/node
RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm && \
    ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx

RUN mkdir -p "/.npm" && chown -R nobody.nobody /.npm

# Switch back to non-root user
USER nobody
TrafeX commented 4 months ago

Hi @maxacarvalho,

It might be that you switch to early to the nobody user. I would remove that until the last line and see what it does