Set Up Laravel on Docker in MacOS: A Complete Guide

Updated

Laravel PHP framework logo

Use Laravel Sail rather than a hand-written Dockerfile — but install it deliberately, because a fresh Laravel app no longer ships with it.

laravel new my-app          # or: composer create-project laravel/laravel my-app
cd my-app
composer require laravel/sail --dev
php artisan sail:install --with=mysql
./vendor/bin/sail up -d

The hand-written Dockerfile and docker-compose.yml described below are now broken in ways that will stop the build or produce an app that will not boot. Here is what changed and what to do instead.

A Dockerfile pinned to PHP 8.1 will not run current Laravel

A Dockerfile that begins FROM php:8.1-apache fails at the composer step when you install a current Laravel into that image. Creating a real project here with Composer 2.10.1 produced Laravel Framework 13.24.0, and its composer.json requires:

{
  "php": "^8.3",
  "laravel/framework": "^13.8",
  "laravel/tinker": "^3.0"
}

PHP 8.1 does not satisfy ^8.3. Separately, PHP 8.1 is no longer listed on php.net’s supported-versions page at all; the oldest branch still receiving security fixes is 8.2, and that ends 31 December 2026. Do not build new images on either.

Three problems in a hand-written docker-compose.yml

version: '3.8' — the Compose Specification now heads this key “Version top-level element (obsolete)” and states that it “is only informative you’ll receive a warning message that it is obsolete if used.” Delete the line.

APP_KEY= in the environment: block — this is the one that wastes an afternoon. An environment variable set on the container takes precedence over the value in .env. So you run php artisan key:generate, it writes a key into .env, it reports success, and the app still returns “No application encryption key has been specified” because the empty container-level variable wins. Remove the key from the compose file entirely and let .env own it.

docker-compose build / docker-compose up — Compose v1 was written in Python and is end-of-life. The current command is docker compose, a subcommand of the Docker CLI. Older tutorials’ hyphenated form is what produces “command not found” on a clean install.

What Sail actually is, and what it is not

Sail is not a runtime, a VM, or an alternative to Docker. Reading its source: bin/sail is a shell script that proxies your commands to docker compose against a generated compose file, and sail:install is an Artisan command whose signature is sail:install {--with= : The services that should be included in the installation}. It writes the docker-compose.yml you would otherwise type by hand, wires the matching variables into .env, and adds a Dockerfile per PHP version — the runtimes/ directory in laravel/sail currently carries 8.0 through 8.5. You still need a working Docker engine underneath.

Sail is the officially maintained path (laravel/sail v1.66.0, released 10 August 2026). laravel/sail is not installed by default: a fresh laravel/laravel project created here has fakerphp/faker, laravel/pail, laravel/pao, laravel/pint, mockery/mockery, nunomaduro/collision and phpunit/phpunit in require-dev, and no Sail. Nor is there a docker-compose.yml in the project root until you run sail:install.

You may not need Docker for this at all

The premise that a Mac Laravel developer needs Docker for a database is no longer true by default. Creating a project here, the post-install scripts ran on their own:

> @php -r "file_exists('database/database.sqlite') || touch('database/database.sqlite');"
> @php artisan migrate --graceful --ansi

 INFO  Preparing database.
 INFO  Running migrations.
  0001_01_01_000000_create_users_table .. 2.24ms DONE
  0001_01_01_000001_create_cache_table .. 1.23ms DONE
  0001_01_01_000002_create_jobs_table .. 1.85ms DONE

A working, migrated app with no container involved. Laravel now defaults to SQLite. Reach for Sail when you need to match production’s MySQL or Postgres version, or when a teammate’s machine must reproduce yours exactly — not reflexively.

Docker Desktop licensing, checked in August 2026

Licensing matters if you are installing Docker Desktop on a work machine. Docker’s own documentation states that small businesses — “fewer than 250 employees AND less than $10 million in annual revenue” — may use Docker Desktop free; professional use in larger organizations requires a paid Docker Pro, Team, or Business subscription. Current list pricing on docker.com: Personal $0, Pro $9/month billed annually, Team $15/month billed annually, Business $24/month.

If that applies to you, two alternatives run the same containers and the same ./vendor/bin/sail commands:

Option Version checked 10 Aug 2026 Note
OrbStack 2.2.3 (Homebrew cask) Commercial, Mac-only; markets itself as a Docker Desktop replacement
colima 0.10.3 (Homebrew formula; upstream release v0.10.3, 4 June 2026) Open source, CLI only, needs the docker client installed separately

Installing Composer and running commands in the container

Installing Composer with curl -sS https://getcomposer.org/installer | php and no signature check pipes an unverified installer straight into an interpreter. On a Mac, brew install composer avoids the whole question.

Without Sail, you find your container’s name with docker ps and then run docker exec -it <container_name> bash. With Sail there is no name to look up:

./vendor/bin/sail artisan migrate
./vendor/bin/sail composer install
./vendor/bin/sail shell

What was run here and what was not

No Docker was involved in producing this page. There is no Docker engine on the machine used, so sail up, the container build, the port mapping and the browser check at localhost were not executed, and no claim above depends on their having been. The measured part of this page can be rerun without Docker: /verify/install-laravel-on-docker-mac.sh creates a real project with composer create-project laravel/laravel in a scratch directory, re-queries Packagist, php.net, the Compose spec, GitHub and Homebrew for the versions and wording quoted above, and reports every container step as skipped.

What was executed, on macOS 26.6 with PHP 8.5.8 and Composer 2.10.1: composer create-project laravel/laravel, which produced Laravel Framework 13.24.0, ran its migrations against SQLite, and yielded the dependency lists and the absence of a docker-compose.yml quoted above. Attempting composer require laravel/sail was deliberately not completed here, so Sail’s behaviour is described from its published source (bin/sail, src/Console/InstallCommand.php, the runtimes/ directory) rather than from a run. Version and licensing figures come from the Packagist API, the GitHub API, Homebrew, php.net and docker.com, all retrieved on 10 August 2026.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.