Content Index
- What is Laravel Sail?
- Any recent Laravel project can use Sail
- Install Docker
- ️ Step 1. Install Laravel Sail in an existing project
- ⚙️ Step 2. Initialize Sail in the project
- Step 3. Spin up the project with Sail
- Running commands: Migrations and Artisan inside the container
- Extra: Run Sail in background (detached) mode
- Common error fix: configuration file not found
- Basic Sail command reference
- In short, what is Laravel Sail and why use it?
Unlike other frameworks that require the developer to manually create Dockerfile and docker-compose.yml files, Laravel takes a disruptive path: it provides an official tool called Laravel Sail that takes care of creating and managing the entire Docker environment for us, transparently and friction-free.
Previously we explored the collections system in Laravel. With all that prior knowledge, we already have the necessary ecosystem to take the next step and work with Docker through Sail.
What is Laravel Sail?
Laravel Sail is a lightweight command-line interface (CLI) designed to interact with the Docker environment that, since Laravel 8, became established as the default development environment. Sail provides an exceptional starting point for creating Laravel applications with PHP, MySQL, and Redis, and best of all is that you don't need any prior Docker experience to get started.
In essence, Sail is made up of two key elements: the docker-compose.yml file and a navigation script stored in the project root. That script exposes a CLI with convenient methods to interact with the Docker containers defined in that configuration file.
Sail emerges as Laravel's newest development environment starting from version 8 and comes to sit alongside other official solutions like Homestead (aimed at Windows/Linux with Vagrant) and Valet (for macOS), in addition to very popular community alternatives like Laragon (which is the one I use on Windows), Laradock, and Vessel.
Laravel Sail is built on Docker, the technology that leverages containers to package applications so they can run quickly and consistently on any operating system, eliminating the classic "it works on my machine" problem.
Sail's future looks bright: the official Laravel documentation already presents it as the preferred way to install and run projects locally, a spot that Homestead and Valet occupied for years.
Laravel Sail is compatible with macOS, Linux, and Windows (via WSL2).
To follow all the installation and setup steps we will see next, you can complement it with the official Laravel Sail documentation, which is very well maintained.
Any recent Laravel project can use Sail
The first thing we need is, of course, to have a Laravel project. To give you context: I have projects on Windows that I develop with Laragon (without Sail) and others on Mac where I use Laravel Sail. They are the exact same projects, but running in completely different environments. This shows the flexibility of the ecosystem.
Laravel Sail, as a lightweight CLI for interacting with Laravel's default Docker environment, lets you choose which services should be configured in the project's docker-compose.yml file. Some of the available options include mysql, pgsql (PostgreSQL), redis, memcached, meilisearch, selenium, and mailhog.
If you are creating a project from scratch, you can specify the desired services directly in the installation command. For example, to include only MySQL and Redis:
$ curl -s "https://laravel.build/example-app?with=mysql,redis" | bashIf you don't pass the with parameter, Sail will configure the default stack that includes mysql, redis, meilisearch, mailhog, and selenium. This flexibility gives you very detailed control over which services consume resources on your machine.
Install Docker
Although we are not going to interact directly with Docker at a low level, it remains a fundamental dependency for Sail to work. You must download and install it from the official Docker website.
In the case of Windows, you must have features like hardware virtualization and Windows Subsystem for Linux (WSL2) enabled, which are what allow Docker to run Linux containers natively. The official Docker documentation covers these steps in detail. If you also want to understand Docker in depth, we also have a Docker Course for Developers available.
️ Step 1. Install Laravel Sail in an existing project
If you want to add Sail to an already existing Laravel application, you simply install it like any other Composer package. Of course, these steps assume your local environment already lets you install Composer dependencies (that is, you have PHP available on your machine):
$ composer require laravel/sail --devSail is installed as a development dependency (
--dev), since it is not a package you need in production, where Docker is not part of the usual deployment stack.
⚙️ Step 2. Initialize Sail in the project
With the package installed, the next step is to run the Artisan command that generates the necessary configuration files for Docker inside your project:
$ php artisan sail:installWhen running this command, two important things happen:
- Sail asks about the database: It will present a menu to select the engine you want to use (such as
mysqlorpgsql). Keep in mind that SQLite doesn't make much sense inside an isolated container, since it is a local file database. - Sail generates
docker-compose.yml: This file stays in the project root and is what defines all the containers and services that will be spun up. You will also see thedocker/directory with customDockerfiles per PHP version.
Step 3. Spin up the project with Sail
With the docker-compose.yml file generated, you already have everything needed to start the environment. Run the following command from your project root:
$ ./vendor/bin/sail up- When running
sail up, Docker downloads the necessary images (if you don't have them yet), creates the containers defined indocker-compose.yml, and starts them. You will see the download traces for images like Ubuntu in your terminal. - Once up and running, you can check in the Docker Desktop dashboard that the image and containers are active and running.
You can check your .env file and you'll see that Sail already automatically configured the credentials for the selected database:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=sail
DB_PASSWORD=passwordNotice
DB_HOST=mysql: Sail doesn't point to127.0.0.1but to the service name defined indocker-compose.yml. Docker containers communicate with each other using the service name as the hostname inside Docker's internal network.

Running commands: Migrations and Artisan inside the container
Once the project is running (normally accessible at http://localhost), it is very likely that the application shows an error indicating the database is unavailable or the tables don't exist. This is completely normal: we haven't run the migrations yet.
To run migrations (or any Artisan command) inside the container, you must replace php artisan with sail artisan:
$ ./vendor/bin/sail artisan migrateWhy sail artisan instead of php artisan? The sail command communicates with the application container and runs the command inside that isolated environment, where the database and all dependencies are configured. If you used php artisan directly from your machine, you would be using the locally installed PHP interpreter, which has no visibility into the services running inside Docker (such as the container's MySQL server).
After running the migrations successfully, the application should load without errors in the browser, confirming it is being served entirely by the Docker environment managed by Sail.
Stop the environment
To stop all containers and free up system resources, run:
$ ./vendor/bin/sail downYou can also interrupt the process directly with Ctrl + C in the terminal where Sail is running, although
sail downis the cleanest way to do it.
Extra: Run Sail in background (detached) mode
If you don't want your terminal blocked with container logs, you can start Sail in detached mode using the -d option. The containers will run in the background:
$ ./vendor/bin/sail up -dCommon error fix: configuration file not found
If when trying to start Sail you see the following error:
ERROR:
Can't find a suitable configuration file in this directory or any
parent. Are you in the right directory?
Supported filenames: docker-compose.yml, docker-compose.yaml, compose.yml, compose.yamlThe problem is clear: Sail was not initialized in the project. The docker-compose.yml file does not exist because you never ran the installation command. The solution is simply to pick back up from Step 2:
$ php artisan sail:installAnd follow the steps indicated above to select the services and generate the configuration.
Basic Sail command reference
With Sail you can run practically any command you need inside the Docker environment: php commands, artisan, composer, npm, and, of course, Sail's own commands that wrap docker-compose. The key is to always use the ./vendor/bin/sail prefix (or simply sail if you set up the alias) instead of native system commands.
Fundamental rule: any tool that is part of the Docker environment (such as mysql, redis, or php) must be invoked through Sail so the command runs inside the corresponding container. For example, instead of php artisan migrate, always use sail artisan migrate.
Essential Sail commands (equivalents to their docker-compose counterparts):
sail ps(equiv.docker-compose ps): View the status of all running containers.sail up(equiv.docker-compose up): Create and start the containers.sail up -d(equiv.docker-compose up -d): Start the containers in background mode.sail down(equiv.docker-compose down): Stop and remove the containers.sail artisan migrate: Run migrations inside the application container.sail composer require [paquete]: Install Composer dependencies inside the container.sail npm install: Install Node dependencies inside the container.sail shell: Open an interactive shell session inside the main application container. Very useful for debugging or exploring the container's file system.
In short, what is Laravel Sail and why use it?
Laravel Sail is a package installable via
composerthat offers a command-line interface to spin up and manage Laravel projects on Docker. It abstracts away all the Docker configuration complexity you would have to do manually, automatically generating the necessarydocker-compose.ymlandDockerfiles.Sail lets you set up a full project needing to install practically nothing at the operating system level: only Docker is strictly necessary (and in some cases,
PHPfor the steps before the container is up and running). The web server, database, Redis, and all other dependencies run inside Docker containers.On Linux and macOS it works friction-free. On Windows, you must enable and configure the Linux subsystem (
WSL2) beforehand, which is the engine on which Docker Desktop runs on that operating system.Personally, it is one of my favorite environments and the one I use on macOS to develop the projects for my books and courses. It is very lightweight, stable, and easy to use. The only point to keep in mind when starting it up is making sure the ports Sail uses aren't occupied by other services: mainly port
80(web server) and port3306(MySQL). Both are configurable per project indocker-compose.ymlif you need to keep them running in parallel with other services.
Next step: learn about folder and file structure in Laravel.