Docker image to scaffold / install Laravel projects without having Laravel installed on the system.
This project makes use of:
- Docker Hub
laurencerawlings/laravel:latest - GitHub Container Registry
ghcr.io/laurencerawlings/laravel:latest
The Docker image will give you access to the following binaries:
phpcomposerlaravel
In the following examples replace my_project with a name of your choice (no spaces).
Interactive example:
NAME=my_project; docker run -it --rm \
--pull=always \
-v "$(pwd)":/opt \
laurencerawlings/laravel \
"laravel new $NAME && cd $NAME && php artisan sail:install"Non-interactive example:
NAME=my_project; docker run --rm \
--pull=always \
-v "$(pwd)":/opt \
laurencerawlings/laravel \
"laravel new --no-interaction $NAME --database pgsql && cd $NAME && php artisan sail:install --with=pgsql,mailpit"View available Laravel new options:
docker run --rm \
--pull=always \
laurencerawlings/laravel \
"laravel new --help"Note
Laravel new --git, --branch, --github and --organization options will not work due to git and the GitHub CLI not being installed in the image.
To view current available Sail services view this GitHub file, or run in interactive mode.
Install Laravel in to an existing / cloned project:
- Run in the root of the project
docker run --rm \
--pull=always \
-v "$(pwd)":/opt \
laurencerawlings/laravel \
"composer install --ignore-platform-reqs && cp .env.example .env && php artisan key:generate"Note
The following commands require a bash alias for sail which can be added to your terminal profile for persistence:
alias sail='sh $([ -f sail ] && echo sail || echo vendor/bin/sail)'
After running new / install here are some useful commands to run:
- Run in the root of the project
sudo chown -R $USER: .
sail up -d
sail artisan migrate
sail npm install && sail npm run build
sail npm run dev- Replace
my_projectwith your projects name (no spaces) - Optionally update the hosts file with:
127.0.0.1 my_project.test - Visit http://my_project.test or http://localhost
Add these shortcuts to you .bashrc / .zshrc or equivalent, change the function names to whatever you like:
# Interactive Laravel install
function laravel_new() {
docker run -it --rm \
--pull=always \
-v "$(pwd)":/opt \
laurencerawlings/laravel \
"laravel new $1 && cd $1 && php artisan sail:install"
cd $1
sudo chown -R $USER: .
}
# Composer dependency install
function laravel_install() {
docker run --rm \
--pull=always \
-v "$(pwd)":/opt \
laurencerawlings/laravel \
"composer install --ignore-platform-reqs && cp .env.example .env && php artisan key:generate"
sudo chown -R $USER: .
}
# Non-interactive Laravel install
function laravel_new_manual() {
docker run --rm \
--pull=always \
-v "$(pwd)":/opt \
laurencerawlings/laravel \
"laravel new --no-interaction $@"
cd $1
sudo chown -R $USER: .
}
# Non-interactive Laravel install with favourite defaults
function laravel_new_default() {
docker run --rm \
--pull=always \
-v "$(pwd)":/opt \
laurencerawlings/laravel \
"laravel new --no-interaction $1 --database pgsql --livewire --pest && cd $1 && php artisan sail:install --with=pgsql,mailpit"
cd $1
sudo chown -R $USER: .
}Usage:
laravel_new my_project
laravel_install
laravel_new_default my_projectCreate mock php and composer binaries so VSCode extensions can find them:
/usr/local/bin/php
./vendor/bin/sail php $@/usr/local/bin/composer
./vendor/bin/sail composer $@Make them executable:
sudo chmod +x /usr/local/bin/php
sudo chmod +x /usr/local/bin/composerUpdate VSCode settings:
{
"php.validate.executablePath": "/usr/local/bin/php"
}Additionally, adding this line to your .env will speed up sail execution time a bit:
SAIL_SKIP_CHECKS=true