Laravel sail (docker) bash alias not remembering

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# The Persistent Problem: Why Your Laravel Sail Alias Keeps Disappearing As a senior developer working with containerized applications like Laravel Sail, we often aim for maximum efficiency. We want short, readable commands that save us time. Setting up aliases is a classic way to achieve this. However, when dealing with shell configurations, especially within the dynamic environment of Docker and WSL (Windows Subsystem for Linux), persistence can become a frustrating hurdle. I’ve encountered this exact scenario: setting up an alias for `sail` seems straightforward, but every time I reboot or open a new terminal session on my Ubuntu machine, the alias vanishes. This forces me to type the long path `./vendor/bin/sail` repeatedly, defeating the purpose of the setup. This post will diagnose why this happens and provide robust, persistent solutions so you can enjoy smooth workflow within your Laravel Sail environment. --- ## Diagnosing the Ephemeral Alias Issue The core issue lies in how shell configuration files are loaded. When you define an alias in a file like `.bashrc`, that file is only executed when a new interactive shell session starts (e.g., logging in via SSH or opening a new terminal). If your method of applying the alias isn't correctly integrated into this loading process, or if the environment resetting strips it, it results in an ephemeral setting. The command you attempted to use: ```bash alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail' ``` While syntactically correct for defining an alias, its persistence relies entirely on proper loading and execution within the shell environment. If this line is being executed in a context that doesn't fully initialize all necessary environment variables, or if subsequent system updates reset certain configuration states, the change can be lost upon reboot. ## Solution 1: The Standard Persistence Fix (Correct `.bashrc` Implementation) The most reliable way to ensure shell customizations persist across sessions is to place them directly into your shell's startup file, typically `~/.bashrc`. However, simply adding the alias definition might not be enough; we need to ensure the shell correctly interprets and loads these commands. When setting up tools like Laravel Sail, remember that the underlying Docker setup relies on a specific structure. When you are working with container workflows, understanding how your host operating system manages environment variables is crucial, much like understanding how services interact within the broader ecosystem of [laravelcompany.com](https://laravelcompany.com). To ensure maximum stability, always test your modifications by sourcing the file immediately after editing it: ```bash echo "alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'" >> ~/.bashrc source ~/.bashrc ``` By explicitly sourcing the file, you force the current shell to reload the configuration immediately. This practice ensures that the alias is registered every time you open a new terminal, making it persistent across reboots. ## Solution 2: The Robust Alternative – Shell Functions While aliases are convenient for simple command substitutions, complex commands—especially those involving conditional logic like your check (`[ -f sail ]`) and piping—are often better handled using **shell functions**. Functions offer superior persistence and complexity management because they execute as a single block of code, rather than relying on the shell’s internal alias mechanism. A shell function is defined directly in `.bashrc` and executes exactly as intended every time the shell loads, offering more control over the execution flow: ```bash # Add this to ~/.bashrc function sail() { if [ -f sail ]; then bash sail else bash vendor/bin/sail fi } ``` **Why Functions are Better:** 1. **Clarity:** The logic is explicit and easier to debug than complex alias syntax. 2. **Robustness:** They handle arguments and execution context more reliably across different shell environments. 3. **Persistence:** Since they are defined as standard shell functions within the startup file, they persist indefinitely, regardless of session resets. ## Conclusion The disappearance of your `sail` alias is a common frustration stemming from the nuances of shell environment loading rather than an error in the Laravel Sail setup itself. For persistent and robust workflow management in any Linux or Docker-based environment, favor **shell functions** over simple aliases for complex commands. By placing these definitions correctly in your `.bashrc` file and ensuring you source the file upon startup, you establish a stable foundation that will last through every system refresh. Happy coding!