Monday, May 19, 2025Dockerize Laravel with Sail
Keven Client A. Cataluña @LinkedIn
Introduction

This guide demonstrates how to Dockerize a Laravel application using Sail, including publishing the docker-compose.yml file and configuring a shell alias for easy access to Sail commands.

Steps1. Publish the docker-compose.yml file
    php artisan sail:install
  
      ┌ Which services would you like to install? ───────────────────┐
  │ › □ mysql                                                    │
  │   □ pgsql                                                    │
  │   □ mariadb                                                  │
  │   □ redis                                                    │
  │   □ memcached                                                │
  │   □ meilisearch                                              │
  │   □ typesense                                                │
  │   □ minio                                                    │
  │   □ mailpit                                                  │
  │   □ selenium                                                 │
  │   □ soketi                                                   │
  └────────────────────────────────────────────────── 0 selected ┘

  ┌ Which services would you like to install? ───────────────────┐
  │ None                                                         │
  └──────────────────────────────────────────────────────────────┘
  
2. Add the shell alias
~/.bashrc
    # Laravel Sail
alias sail='sh $([ -f sail ] && echo sail || echo vendor/bin/sail)'
  
3. Restart the terminal
    source ~/.bashrc
  
4. Start all Docker containers in the background
    sail up -d
  
      [+] Running 2/2
   ✔ Network laravel_sail              Created                    0.8s
   ✔ Container laravel-laravel.test-1  Started                    1.2s
  
5. Navigate to http://localhost and you should see the default Laravel landing page