Skip to main content

Setting Up Laravel with Docker Compose

In this guide, you will learn how to quickly set up your Laravel application on Ubuntu 22.04 using Docker Compose with three separate containers (PHP-FPM, MySQL, Nginx). Your development environment will be fully isolated and portable.

What You'll Learn

You will learn how to containerize your Laravel application with Docker Compose. You'll run PHP-FPM, MySQL and Nginx services in three separate containers, creating an isolated and portable development environment.

Prerequisites

Before starting, make sure the following tools are installed:

  • Ubuntu 22.04 operating system (with a sudo-enabled user)
  • Docker
  • Docker Compose

Step 1 — Create Project Directory

mkdir ~/laravel-docker && cd ~/laravel-docker

Create the necessary subdirectories:

mkdir -p docker/nginx docker/php

Step 2 — Create Docker Compose File

Create the docker-compose.yml file:

version: '3.8'

services:
app:
build:
context: .
dockerfile: docker/php/Dockerfile
container_name: laravel-app
volumes:
- ./src:/var/www/html
networks:
- laravel-network

nginx:
image: nginx:alpine
container_name: laravel-nginx
ports:
- "80:80"
volumes:
- ./src:/var/www/html
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- app
networks:
- laravel-network

mysql:
image: mysql:8.0
container_name: laravel-mysql
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: secret
volumes:
- mysql-data:/var/lib/mysql
networks:
- laravel-network

volumes:
mysql-data:

networks:
laravel-network:
driver: bridge
info

This is a sample English translation. The full content will be added later.