longestdrive's avatar

Laravel Sail/Docker composer issues

I've now set up a Laravel development environment using Sail (switching from Homestead) to try it out. I've got a very basic app running but I'm having problems with composer creating different errors depending on packages installed.

I'm using sail composer... to run the composer commands

I've just tried to install barryvdh/laravel-debugbar. When I do it comes up with an error:

In RecursiveDirectoryIterator.php line 48:
                                                                                                                                      
  RecursiveDirectoryIterator::__construct(/var/www/html/vendor/barryvdh/laravel-debugbar): Failed to open directory: Not a directory  

The folder does exist in my project.

If I then remove the package I then get a new error:

In PhpFileParser.php line 51:
                                                                                                                                                        
  File at "/var/www/html/vendor/laravel/framework/src/Illuminate/Validation/ClosureValidationRule.php" does not exist, check your classmap definitions  

And on checking in the project again that file exists

I've had similar errors with other packages and needed to remove and reinstall, removing the vendor directory completely as well - something is not right when running composer within Docker

I'm also starting to get namespace errors for my models after this aborted install - Models/User not found

Here is my composer file:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.1",
        "barryvdh/laravel-ide-helper": "*",
        "blade-ui-kit/blade-ui-kit": "^0.4.0",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^10.0",
        "laravel/jetstream": "^3.1",
        "laravel/sanctum": "^3.2",
        "laravel/tinker": "^2.8",
        "livewire/livewire": "^2.11",
        "maatwebsite/excel": "^3.1"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/pint": "^1.0",
        "laravel/sail": "^1.18",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^7.0",
        "phpunit/phpunit": "^10.0",
        "spatie/laravel-ignition": "^2.0"
    },
    "autoload": {
        "psr-4": {
            "App\": "app/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true,
            "php-http/discovery": true
        }
    },
    "minimum-stability": "stable",
    "prefer-stable": true
}


I'm not sure where to start looking to fix and ensure composer is stable

0 likes
2 replies
LaryAI's avatar
Level 58

It seems like there might be an issue with the Docker container not having the correct permissions to access the vendor directory. One solution could be to run the composer commands with elevated permissions using the sudo command.

Another solution could be to try deleting the vendor directory and running sail composer install again.

If neither of these solutions work, it might be worth checking the Docker logs for any errors or trying to rebuild the Docker container.

Here's an example of how to run the composer install command with elevated permissions:

sail sudo composer install
longestdrive's avatar

I decided to try and delete the app and start again - however it is not installing a new app using the same name - I get errors that the build can't either create or access opt/vendor

Failed to extract fakerphp/faker: (50) '/usr/bin/unzip' -qq '/opt/golf-app/vendor/composer/tmp-598b5bf8b469ee376878928a88eb1bca' -d '/opt/golf-app/vendor/composer/a94b8f2e'

The build is trying to install to the opt folder rather than the project folder - is that expected behaviour?

I've removed all images from docker and cleared the docker cache using docker builder prune -a

Strangely I did get a build if I used another app name - suggesting there's some legacy config somewhere that needs purging - I just don't know where :(

Please or to participate in this conversation.