PortGate

Blueprints · Laravel & PHP

Production 30 min · Docker

Laravel multi-stage hardened Docker Compose

A production compose file for PHP-FPM as UID 10001, Nginx, Redis, and a Horizon worker. Published ports stay on localhost and every service drops new privileges.

Live config

Baked-in protections

Step 1 · yaml

compose.prod.yaml

/opt/laravel/compose.prod.yaml

Build the app image so the FPM user is 10001. Horizon uses the same image. Database {{DB_NAME}} is an application setting, not a container published to the host.

services:
  app:
    build:
      context: .
      target: app
    user: "10001:10001"
    security_opt:
      - no-new-privileges:true
    read_only: true
    tmpfs:
      - /tmp
    volumes:
      - app-storage:/var/www/html/storage
    restart: unless-stopped
  nginx:
    image: nginx:1.27-alpine
    depends_on:
      - app
    ports:
      - "127.0.0.1:8080:80"
    security_opt:
      - no-new-privileges:true
    volumes:
      - ./docker/nginx.conf:/etc/nginx/conf.d/default.conf:ro
    restart: unless-stopped
  redis:
    image: redis:7
    command: ["redis-server", "--bind", "0.0.0.0", "--protected-mode", "yes"]
    security_opt:
      - no-new-privileges:true
    mem_limit: 256m
    restart: unless-stopped
  horizon:
    build:
      context: .
      target: app
    user: "10001:10001"
    command: ["php", "artisan", "horizon"]
    security_opt:
      - no-new-privileges:true
    restart: unless-stopped
volumes:
  app-storage:

Step 2 · bash

Start command

/opt/laravel/up-prod.sh

Written, not run. Redis is only reachable on the compose network, so the bind address inside the network is not a public port.

#!/bin/sh
set -eu
cd "/opt/laravel"
docker compose -f compose.prod.yaml up -d
docker compose -f compose.prod.yaml ps