Laravel Sail, has a good premisse to create a zero dependency environment, with, php, redis, mariadb etc…
But its instalation require composer, composer require php installed,
is this a paradox?
There are some way to achieve zero dependency, with docker installed?
3
Answers
edit
I was listening to the laravel news podcast yesterday and the people from Laravel created a solution for this problem. They now have a section with a command that spins up a php container to install php dependencies through a container first and move them to your host computer.
As Sail gives you the option to manage the container from the host through Artisan, then no.
If you don’t mind to give up the ability to use Sail in this way and just want to set up a dockerized environment for Laravel, then yes. You can make a container for php in which you copy your project and through volumes maps to the host. You can enter a container (as if using
ssh
) throughdocker-compose exec <service> <command>
, in the repo I linked, the php Dockerfile uses Alpine as the linux distro, which comes with theash
(instead ofbash
) shell. Because of his you can runto enter the container and run commands inside it.
It’s in the documentation here:
https://laravel.com/docs/9.x/sail#installing-composer-dependencies-for-existing-projects
You can use the sail Docker container on its own to bootstrap the process, and run
composer
in that container. The main part of that documentation is this command:There is a
laravelsail/php7.4:latest
container too, if you are not yet using PHP 8.Edit: the above used to work, but now appears to be broken. The container does not have a
sail
user or group, and that leads to permission problems.When the
sail up
command is executed, the entrypoint to the PHP container will take the current user ID and group ID, then assign them to thesail
user and group. That happens (now) in thesail up
command and not thelaravelsail
container listed above.I’m not sure when this changed. For now you can run the above without the
-u
option, and set up the application as root within the container. Permissions will need to be manually fixed after that.Also note the
laravelsail/php7.3
container only hascomposer
v1.8 installed initially, but is easily updated usingcomposer self-update
.This command worked for me on windows: