Learn how to run Laravel Dusk with Sail the right way. Step-by-step setup, Docker tweaks, test database isolation, and exact commands that actually work. Our 24/7 Laravel Live Support Team is always here to help you.


If you work with Laravel long enough, browser testing becomes unavoidable. Buttons fail. Forms break. A tiny UI change takes production down. That’s exactly where laravel sail dusk fits in. It lets you run real browser tests using Chrome, inside Docker, without installing Selenium or messing up your system.

So, instead of vague guides and half-working snippets, let’s walk through a clean, proven setup that developers actually use.

laravel sail dusk

Why Laravel Dusk With Sail Makes Sense

Laravel Dusk already handles browser automation beautifully. Now add Sail, and things get simpler. You don’t install ChromeDriver. You don’t manage Selenium locally. Everything runs in containers.

More importantly, laravel sail dusk keeps your development environment clean and repeatable. If it works on your machine, it works for the team.

Steps

Enable Selenium in Sail

First, open your docker-compose.yml file. Uncomment or add the Selenium service:

selenium:
image: 'selenium/standalone-chrome'
extra_hosts:
- 'host.docker.internal:host-gateway'
volumes:
- '/dev/shm:/dev/shm'
networks:
- sail

Next, make sure your laravel.test service depends on Selenium:

depends_on:
- mysql
- redis
- selenium

This ensures the browser is ready before tests run.

Install Laravel Dusk

Now install Dusk inside Sail:

sail composer require --dev laravel/dusk
sail php artisan dusk:install

After that, publish Sail’s Docker files so you can customize them:

sail artisan sail:publish

At this point, laravel sail dusk is installed, but we still need database isolation.

Ship UI changes with confidence

Chat animation


Create a Separate Database for Dusk

Running browser tests on your dev database is risky. One failed test can wipe data. Laravel Dusk solves this by loading a different environment file.

Create .env.dusk.local and add:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:EUzC7XceXTxeQwT+eRMEysZwrs6e/pHjO2xYUNZTggo=
APP_DEBUG=true
APP_URL=http://laravel.test
DB_CONNECTION=mysql
DB_HOST=mysql.test
DB_DATABASE=dusk_test
DB_USERNAME=sail
DB_PASSWORD=password

This tells laravel to use a dedicated test database.

Add a MySQL Test Service

Inside docker-compose.yml, add a new service:

mysql.test:
image: "mysql:8.0"
ports:
- "${FORWARD_DB_PORT:-3307}:3306"
environment:
MYSQL_ROOT_PASSWORD: "${DB_PASSWORD}"
MYSQL_DATABASE: "${DB_DATABASE}_test"
MYSQL_USER: "${DB_USERNAME}"
MYSQL_PASSWORD: "${DB_PASSWORD}"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
volumes:
- "./docker/mysql.test/init:/docker-entrypoint-initdb.d"
tmpfs:
- "/var/lib/mysql"
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s

Then create this file:

./docker/mysql.test/init/01-create_dusk_database.sql

CREATE DATABASE IF NOT EXISTS `dusk_test`;
GRANT ALL PRIVILEGES ON dusk_test.* TO 'sail'@'%';

Now restart Sail:

sail up -d
Run Your Dusk Tests

Finally, run the tests:

sail dusk

You’ll see Chrome launch inside Docker and tests execute against the test database. No data loss. No manual setup.

That’s its real power.

Conclusion

Browser testing doesn’t need to be painful. With the right Sail setup, laravel sail dusk becomes predictable, fast, and safe. More importantly, it gives confidence before every deploy. Once this is in place, UI bugs stop being surprises and start becoming test failures, exactly where they belong.