MANUAL

Docker for your Laravel app

Docker for your Laravel app

With Docker, your app runs in containers: isolated mini-environments with exactly the right version of PHP, database and extras. If it works for you, it will also work for your colleague and on the server. You don’t need to install PHP, MySQL and Redis on your computer yourself.

A few words you’ll often come across:

01

Step 1: Install Docker

Then check in the terminal:

docker --version
docker compose version

02

Step 2 (the easiest route): Laravel Sail

Laravel has its own Docker setup: Sail. From your project directory:

composer require laravel/sail --dev
php artisan sail:install      # kies bijvoorbeeld mysql en redis
./vendor/bin/sail up -d       # start alles op de achtergrond

Your app is now running on http://localhost.. You can execute commands via Sail:

./vendor/bin/sail artisan migrate
./vendor/bin/sail composer install
./vendor/bin/sail npm run dev
./vendor/bin/sail down        # stoppen

Tip: create an alias called sail so you don’t have to keep typing ./vendor/bin/.

03

Step 2 (alternative): your own compose.yaml

If you want to decide for yourself what plays, a simple setup would look like this:

services:
  app:
    build: .
    ports:
      - "8000:8000"
    volumes:
      - .:/var/www/html
    env_file: .env
    depends_on:
      db:
        condition: service_healthy
  db:
    image: mysql:8.4
    environment:
      MYSQL_DATABASE: app
      MYSQL_ROOT_PASSWORD: secret
    volumes:
      - dbdata:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      retries: 5
volumes:
  dbdata:

Please note: in .env, set DB_HOST=db (the name of the service), not 127.0.0.1. Containers locate each other by name.

04

The commands you really need

Command What it does
docker compose up -d Start everything (-d = in the background)
docker compose ps Which containers are running?
docker compose logs -f app Live logs from the app (-f = follow)
docker compose exec app php artisan migrate Running a command inside the container
docker compose exec -it app bash Open a shell in the container
docker compose down Stop everything (data is retained)
docker compose build --no-cache Rebuild after a change to the Dockerfile

05

Be careful with these commands

Only use them if you are certain you no longer need the data. Do not let your AI assistant run them without asking first. The docker-destructive-guardrails skill can help with this.

06

Common problems

07

Need help?

Would you like to have your Laravel app professionally set up in Docker, including a production-ready configuration? This falls under Custom software and web applications.

08

Skills

09

Related services