{"id":705,"date":"2025-09-21T17:59:00","date_gmt":"2025-09-21T17:59:00","guid":{"rendered":"https:\/\/1v0.net\/blog\/?p=705"},"modified":"2025-09-21T18:00:17","modified_gmt":"2025-09-21T18:00:17","slug":"laravel-sail-a-simple-docker-environment-for-laravel","status":"publish","type":"post","link":"https:\/\/1v0.net\/blog\/laravel-sail-a-simple-docker-environment-for-laravel\/","title":{"rendered":"Laravel Sail: A Simple Docker Environment for Laravel"},"content":{"rendered":"\n<p><strong>Laravel Sail<\/strong> is the official Docker-based development environment for Laravel. It provides a simple command-line interface to start and manage a full PHP, MySQL, Redis, MailHog, and more stack without needing to install these services directly on your system. Sail makes it easy for teams to work with the same setup across Windows, macOS, and Linux.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>When I started collaborating with a distributed team on a Laravel project, one of the biggest challenges we faced was keeping our local environments consistent. Some developers were on Windows, others on macOS, and a few on Linux. Everyone had different PHP versions, MySQL setups, and node configurations. Debugging issues caused by environment mismatches became a nightmare, and we wasted valuable time just trying to align setups.<\/p>\n\n\n\n<p>That\u2019s when we introduced <strong>Laravel Sail<\/strong> into our workflow. Instead of installing PHP, Composer, and databases manually, we spun up the entire stack with Docker using Sail. Suddenly, every team member had the same environment, regardless of their operating system. It felt like a huge weight was lifted off our shoulders. I didn\u2019t have to explain how to install Redis or MailHog anymore \u2014 Sail handled it all out of the box.<\/p>\n\n\n\n<p>What I loved most was how easy it was to run Artisan, Composer, and even NPM commands through Sail without touching my system setup. Over time, I learned to customize the <code>docker-compose.yml<\/code> file, adding services like Meilisearch and Selenium for browser testing. It turned into a portable development environment that made collaboration seamless. Looking back, adopting Sail was one of the smoothest decisions we ever made for productivity and sanity in Laravel development.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Installing Laravel Sail<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">curl -s https:<span class=\"hljs-comment\">\/\/laravel.build\/example-app | bash<\/span>\ncd example-app\n.\/vendor\/bin\/sail up<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This command creates a new Laravel project, installs Sail, and boots the Docker containers. The default stack includes PHP, MySQL, Redis, MailHog, and more.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Running Commands with Sail<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">.\/vendor\/bin\/sail artisan migrate\n.\/vendor\/bin\/sail composer <span class=\"hljs-built_in\">require<\/span> laravel\/sanctum\n.\/vendor\/bin\/sail npm install &amp;&amp; .\/vendor\/bin\/sail npm run dev<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>These commands allow you to run Artisan, Composer, and NPM inside the Sail environment. This way your host machine doesn\u2019t need PHP or Node installed \u2014 Sail handles it all within Docker.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Examples for PHP, MySQL, Redis and MailHog<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># Run a PHP command inside the Sail container<\/span>\n.\/vendor\/bin\/sail php -v\n\n<span class=\"hljs-comment\"># Connect to the MySQL database<\/span>\n.\/vendor\/bin\/sail mysql -u root -p\n\n<span class=\"hljs-comment\"># Open a Redis CLI session<\/span>\n.\/vendor\/bin\/sail redis-cli\n\n<span class=\"hljs-comment\"># Access MailHog (fake email server)<\/span>\nhttp:<span class=\"hljs-comment\">\/\/localhost:8025<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>With these commands, you can quickly interact with the core services Sail provides. Run PHP commands without installing PHP locally, manage your MySQL database directly inside the container, debug Redis queues, and view outgoing emails in MailHog via its web UI.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Real-World Use Cases<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># Run a Redis queue worker<\/span>\n.\/vendor\/bin\/sail artisan queue:work\n\n<span class=\"hljs-comment\"># Send a test email (check in MailHog)<\/span>\n.\/vendor\/bin\/sail tinker\n&gt;&gt;&gt; Mail::raw(<span class=\"hljs-string\">'Hello from Sail!'<\/span>, fn($m) =&gt; $m-&gt;to(<span class=\"hljs-string\">'test@example.com'<\/span>));<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>These examples show how Sail makes development practical. You can process jobs using Redis queues directly inside the container, and test email delivery with MailHog before sending anything to real users. This workflow improves reliability while keeping your system isolated and clean.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Customizing Sail<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># docker-compose.yml<\/span>\n\nservices:\n  laravel.test:\n    build:\n      context: .\/vendor\/laravel\/sail\/runtimes\/<span class=\"hljs-number\">8.2<\/span>\n    ports:\n      - <span class=\"hljs-string\">'80:80'<\/span>\n    volumes:\n      - <span class=\"hljs-string\">'.:\/var\/www\/html'<\/span>\n  mysql:\n    image: <span class=\"hljs-string\">'mysql:8.0'<\/span>\n  redis:\n    image: <span class=\"hljs-string\">'redis:alpine'<\/span>\n  meilisearch:\n    image: <span class=\"hljs-string\">'getmeili\/meilisearch:latest'<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You can extend Sail by editing the <code>docker-compose.yml<\/code> file. Here we\u2019ve added Meilisearch for search functionality alongside MySQL and Redis. Sail makes it easy to spin up additional services without complex configuration.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Tips and Tricks<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use <code>.\/vendor\/bin\/sail up -d<\/code> to run containers in the background.<\/li>\n\n\n\n<li>Add Sail aliases in your shell config so you can just type <code>sail artisan<\/code>.<\/li>\n\n\n\n<li>For performance on macOS, use Docker\u2019s \u201cVirtioFS\u201d file sharing mode.<\/li>\n\n\n\n<li>Stop services you don\u2019t need (like MailHog) to save system resources.<\/li>\n<\/ul>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Comparison: Sail vs Valet vs Homestead<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Sail<\/th><th>Valet<\/th><th>Homestead<\/th><\/tr><\/thead><tbody><tr><td><strong>Purpose<\/strong><\/td><td>Docker-based environment<\/td><td>Mac-only lightweight dev server<\/td><td>Virtual machine (Vagrant\/VirtualBox)<\/td><\/tr><tr><td><strong>OS Support<\/strong><\/td><td>Windows, macOS, Linux<\/td><td>macOS only<\/td><td>Cross-platform<\/td><\/tr><tr><td><strong>Setup<\/strong><\/td><td>Fast, minimal<\/td><td>Very simple on macOS<\/td><td>Heavier, slower to set up<\/td><\/tr><tr><td><strong>Performance<\/strong><\/td><td>Depends on Docker config<\/td><td>Excellent (native)<\/td><td>Slower (VM overhead)<\/td><\/tr><tr><td><strong>Flexibility<\/strong><\/td><td>Easy to add services (MySQL, Redis, etc.)<\/td><td>Basic PHP + MySQL<\/td><td>Pre-packaged full stack<\/td><\/tr><tr><td><strong>Best Use Case<\/strong><\/td><td>Teams, Docker-friendly workflows<\/td><td>Solo Mac developers<\/td><td>Legacy or VM-based workflows<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>See <a href=\"https:\/\/1v0.net\/blog\/best-laravel-starter-kits-breeze-jetstream-spark-nova-22-more\/\" data-type=\"post\" data-id=\"514\">Best Laravel Starter Kits (Breeze, Jetstream, Spark, Nova &amp; 22 More)<\/a> for the list of laravel starter kits.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Laravel Sail<\/strong> removes the headaches of setting up a local environment by running everything inside Docker. It\u2019s cross-platform, customizable, and team-friendly. Whether you\u2019re building a quick prototype or managing multiple projects, Sail keeps your development consistent and portable. If you want a simple yet powerful way to standardize Laravel development across your team, Sail is the tool to use.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel Sail is the official Docker-based development environment for Laravel. It provides a simple command-line interface to start and manage a full PHP, MySQL, Redis, MailHog, and more stack without needing to install these services directly on your system. Sail makes it easy for teams to work with the same setup across Windows, macOS, and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":709,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[164,163,162,100],"class_list":["post-705","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-docker-for-laravel","tag-laravel-sail","tag-laravel-starter-kits","tag-starter-kits"],"_links":{"self":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/comments?post=705"}],"version-history":[{"count":1,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/705\/revisions"}],"predecessor-version":[{"id":708,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/705\/revisions\/708"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/media\/709"}],"wp:attachment":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/media?parent=705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/categories?post=705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/tags?post=705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}