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?
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.
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
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
) through docker-compose exec <service> <command>
, in the repo I linked, the php Dockerfile uses Alpine as the linux distro, which comes with the ash
(instead of bash
) shell. Because of his you can run
docker-compose exec php ash
to 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:
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
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 the sail
user and group. That happens (now) in the sail up
command and not the laravelsail
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 has composer
v1.8 installed initially, but is easily updated using composer self-update
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With