From 3b47bc34d6e3336de9b93c8e1d2a1e0a7e0c1759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20San=20Jos=C3=A9=20Larsson?= <54620188+leonlarsson@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:44:41 +0200 Subject: [PATCH] Run composer install in dev container Today, when you start a dev container using `curl -s "https://laravel.build/example-app?with=mysql,redis&devcontainer" | bash` (or any version with a dev container I assume), it works great. However, if I push that repo to GitHub and then clone it back down, the dev container will not start. That happens because the docker-compose.yml refers to ./vendor, which of course doesn't exist (yet). I have done some testing on my end, and running this command before creating the dev container ensures that `./vendor/laravel/sail/runtimes/8.3(/Dockerfile)` exists before trying to create the container. The command is from https://laravel.com/docs/11.x/sail#installing-composer-dependencies-for-existing-projects For this to work, you would need to add the following to the .env file: ``` WWWGROUP=1000 WWWUSER=1000 ``` Note: I am completely new to Laravel and somewhat new to Docker. If this is not the fix here, please let me know. --- stubs/devcontainer.stub | 1 + 1 file changed, 1 insertion(+) diff --git a/stubs/devcontainer.stub b/stubs/devcontainer.stub index b96384fb..8c50844a 100644 --- a/stubs/devcontainer.stub +++ b/stubs/devcontainer.stub @@ -19,6 +19,7 @@ } }, "remoteUser": "sail", + "initializeCommand": "docker run --rm -u \"$(id -u):$(id -g)\" -v \"$(pwd):/var/www/html\" -w /var/www/html laravelsail/php83-composer:latest composer install --ignore-platform-reqs", "postCreateCommand": "chown -R 1000:1000 /var/www/html 2>/dev/null || true" // "forwardPorts": [], // "runServices": [],