Sail: A guide to using Laravel with Docker

John Mwakalinga
We Code & We Write
Published in
3 min readNov 7, 2022

A step-by-step guide on how to use Docker with your Laravel project

Photo by Artem Verbo on Unsplash

An application container is made using a technology called Docker. Applications are packaged in these containers to enable seamless operation across all environments (or operating systems) with no further setup or configuration.

Sail offers a Docker development environment for your Laravel application. You may use it to automatically construct a Docker container for your Laravel application, saving you time. By default, it will give you access to a local development environment that includes PHP, MySQL, and Redis, though you can choose the particular services you need. This indicates that in order to begin developing a Laravel application, developers no longer need to perform any additional configuration on their operating system (such as installing PHP, MySQL, a local server, etc.). With Sail, they can get going right away.

Another benefit of Sail is that developers don’t need to bother about installing the right configuration software versions on their computers. With a Sail container, you can easily destroy the existing one and build a new one if there is a compatibility issue, keeping everything enclosed and leaving no traces in your local environment.

Sail will make sharing simple and uncomplicated if you are working on a project with other developers because you won’t need to take into account the operating systems they use.

Sail is the latest endeavor in a long line of Laravel development environments, including Homestead, Valet, Laragon, Takeout, Laradock, and Vessel.

The entire package consists of two files: a docker-compose.yml file that organizes the Docker containers used by your application and a Sail script that gives you a CLI for communicating with these containers. The vendor/bin directory houses the Sail script, whereas the docker-compose.yml file is situated in the project's root directory.

We will discover how to set up and use Laravel Sail in this article. We’ll start a new project and carefully examine a few fundamental Sail commands.

Docker requirement

The only prerequisite for using Sail is having Docker installed on the operating system.

You must install and enable Windows Subsystem for Linux 2 if you use Windows (WSL2). You will be able to run native Linux binary executables on your Windows operating system. Ensure that Docker Desktop is set up to use the WSL2 backend as well.

Otherwise, no prior Docker knowledge is necessary.

Sail installation and configuration

Sail is pre-installed in every new Laravel application. To start it up, just one straightforward command is needed.

To build a new Laravel application, execute the command below:‌

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

The aforementioned command creates the project in the my-docker-app directory. You are welcome to rename that to anything you wish to call your project.

Navigate to the project directory after that:‌

cd my-docker-app

Run the following command to launch Sail:‌

./vendor/bin/sail up

Sail integration into an application already in use

If your local development environment is set up to use Composer, you may easily install Sail in an already-running application:‌

composer require laravel/sail --dev

Following installation, use the following command to publish the docker-compose.yml file for Sail in your project directory:

php artisan sail:install

Finally, execute the following command to launch Sail:

./vendor/bin/sail up

Read the rest of the article at Quid Experience. More to be covered

  • Understanding Laravel Sail and Docker
  • Explore a Laravel Sail Commands
  • Conclusion

--

--

John Mwakalinga
We Code & We Write

Developer. A bit biased to Laravel, JS and TS. I write about software and life topics. 🇹🇿. Checkout https://whenprogramming.com