Sailing operations on Laravel Sail

Tram Ho

In the previous post, we learned how to Install the Laravel dev environment using Docker, easily with Sail , in this article we will go deeper into which Sail to use.

Alias ​​configuration for Sail

By default, Sail calls the vendor/bin/sail script to launch the command line, for example

However, as you can see, it is quite cumbersome. We will create an alias for it by typing this in the terminal

So, the command sail is the whole phrase above and we can quickly type sail up 

To avoid having to type in the alias every time we boot, we should insert it into the profile. Like I use zsh, I put it in ~/.zshrc

Start and shut down the Sail

Laravel Sail’s docker docker-compose.yml file identifies a Docker container that works together to help you build Laravel applications. Each of these containers is an item in the services configuration within your docker-compose.yml .

Before starting Sail, you should make sure that there is no webserver (Nginx, Apache, …) or any other database (MariaDB, MongoDB, …) running on your local. To start all the Docker containers declared in the docker-compose.yml file, simply execute the up command:

This command works almost like php artisan serve , but carries a lot more things like redis , php8 , mysql8 , …

I prefer it to run in the background, so I use the command

After the project has started, we can access our product website right at http: // localhost.

Just like php artisan serve , to stop Sail, we just need to press Ctrl + C, if you are like me, run in the background, you need to use the command

Command line interface (CLI) with Sail

When we use Laravel Sail, our application is executed inside a separate Docker container, a private virtual operating system, independent of our own. But okay, it’s hard to let Laravel worry. Laravel Sail provides shortcuts to execute commands directly on your project, without having to run into the Docker container.

Throughout your Documentation , you will see most of the command line examples, which are the need to manipulate Composer, Artisan, Node / NPM. And Sail provides available shortcuts for you to perform operations like this. Instead of composer , php artisan , npm we have sail composer , sail artisan , sail npm respectively.

Container CLI

Sometimes we still need to get into the Docker container, just type:

If we want to open the Tinker to manipulate, we have


Above are some basic operations with Sail, in the next post I will introduce more about the config files of Docker. See you again

Share the news now

Source : Viblo