Overview
Laravel Sail is a light-weight command-line interface for interacting with Laravel's default Docker development environment. Sail provides a great starting point for building Laravel applications without requiring prior Docker experience, and is a perfect fit for Statamic with a few tweaks.
At its heart, Sail is a docker-compose.yml
file and script that is stored at the root of your project. The sail script provides a CLI with convenient methods for interacting with the Docker containers defined by the docker-compose.yml
file.
Laravel Sail is supported on macOS, Linux, and Windows (via WSL2).
Since Sail is the starting point for a new Laravel app, we'll be installing Statamic into a fresh Laravel app.
Installing Docker
If you don't already have Docker installed, head to docker.com/get-started and download the latest version for your OS.
Installing Laravel
Follow the install instructions for creating a fresh Laravel app from their documentation.
On MacOS, run the following command, changing example-app
to anything you want.
curl -s "https://laravel.build/example-app" | bash
Statamic Docker-Composer File
Unless you plan to get fancy and use MySQL with Statamic (yes, you can do that), replace the default docker-compose.yml
file with this one to keep your overhead low.
# For more information: https://laravel.com/docs/sailversion: '3'services: laravel.test: build: context: ./vendor/laravel/sail/runtimes/8.2 dockerfile: Dockerfile args: WWWGROUP: '${WWWGROUP}' image: sail-8.2/app extra_hosts: - 'host.docker.internal:host-gateway' ports: - '${APP_PORT:-80}:80' environment: WWWUSER: '${WWWUSER}' LARAVEL_SAIL: 1 XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}' XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}' volumes: - '.:/var/www/html' networks: - sailnetworks: sail: driver: bridge
Starting and Stopping Sail
Before starting Sail, ensure that no other web servers or databases are running on your local computer.
To start all of the Docker containers defined in your site's docker-compose.yml
file, execute the up command:
./vendor/bin/sail up
To start all of the Docker containers in the background, start Sail in "detached" mode:
./vendor/bin/sail up -d
Once the application's containers have been started, your project can be accessed in the browser at: http://localhost.
To stop all of the containers, press Control
+ C
. Or if the containers are running in the background, use the stop command:
./vendor/bin/sail stop
Installing Statamic
At this point you're running Laravel without Statamic in it. Time to change that.
You can now follow the steps to install Statamic into Laravel.
Keep in mind that commands need to be run inside Sail.
- Instead of php artisan
, run sail artisan
- Instead of composer require
, run sail composer require
- Instead of php please
, run sail artisan statamic
Learn more about Laravel Sail
The Laravel Sail docs cover a lot more of what you can do with Sail. Check them out!