LARAVEL

Laravel Sail Docker Development

April 20, 2024 12 min read

Introduction

Laravel Sail is a light-weight command-line interface for interacting with Laravel's Docker development environment. Sail provides a great starting point for building PHP applications with MySQL, Redis, and more.

Installation

Create a new Laravel project with Sail:

curl -s "https://laravel.build/my-app" | bash

Or install Sail in existing project:

composer require laravel/sail --dev

php artisan sail:install

Getting Started

# Start Sail
./vendor/bin/sail up

# Run in detached mode
./vendor/bin/sail up -d

# Stop Sail
./vendor/bin/sail down

Sail Commands

# Run Artisan commands
./vendor/bin/sail artisan make:model User

# Run Composer
./vendor/bin/sail composer install

# Run npm
./vendor/bin/sail npm install

# Run tests
./vendor/bin/sail test

# Open shell
./vendor/bin/sail shell

Customization

// docker-compose.yml
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.3
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.3/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'

Additional Services

Sail supports multiple services:

  • MySQL / MariaDB
  • PostgreSQL
  • Redis
  • Meilisearch
  • MinIO
  • Mailpit

Summary

Laravel Sail provides an excellent Docker-based development environment for Laravel applications. With simple commands and flexible customization, Sail makes local development consistent across teams.

For more information, check out our other tutorials on Laravel Herd and Laravel Forge.