Back to blog

Dockerizing a Next.js and Laravel Monorepo

DockerLaravelNext.jsDevOps

Setting up a consistent development environment for a full-stack application can be a headache. Different node versions, PHP requirements, and database setups often lead to the classic "it works on my machine" problem.

The solution? Docker.

The Architecture

We want a setup that runs:

  1. A Next.js frontend container.
  2. A Laravel backend container (PHP-FPM).
  3. An Nginx container to serve the backend.
  4. A MySQL container for the database.

Docker Compose

Using docker-compose.yml, we can define all these services in a single file.

version: '3.8'
services:
  frontend:
    build:
      context: ./frontend
    ports:
      - "3000:3000"
    volumes:
      - ./frontend:/app
      - /app/node_modules

  backend:
    build:
      context: ./backend
    volumes:
      - ./backend:/var/www/html

  db:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: myapp
    ports:
      - "3306:3306"

This ensures that every developer on the team runs the exact same environment, eliminating friction and speeding up the onboarding process.