Skip to content

LaurenceRawlings/laravel-installer-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

Laravel Installer Docker

Docker image to scaffold / install Laravel projects without having Laravel installed on the system.

This project makes use of:

Pre-requisites

Usage

The Docker image will give you access to the following binaries:

  • php
  • composer
  • laravel

New

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

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"

Post scaffold / install

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

Bonus

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_project

VSCode Development

Create 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/composer

Update 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

About

Docker image to scaffold / install Laravel project without having Laravel installed on the system

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors