1
0
mirror of https://github.com/docker/awesome-compose.git synced 2025-07-01 01:52:54 +00:00
awesome-compose/react-laravel-mysql
Raghavendra a015fb59f3 React - Laravel - MySQL Compose sample
- Frontend: React Js setup with Vite
- Backend: Laravel
- Database: MySQL

Signed-off-by: Raghavendra N <8619262+raghavendra89@users.noreply.github.com>
2025-01-01 14:28:27 +05:30
..
backend React - Laravel - MySQL Compose sample 2025-01-01 14:28:27 +05:30
db React - Laravel - MySQL Compose sample 2025-01-01 14:28:27 +05:30
frontend React - Laravel - MySQL Compose sample 2025-01-01 14:28:27 +05:30
.env React - Laravel - MySQL Compose sample 2025-01-01 14:28:27 +05:30
compose.yaml React - Laravel - MySQL Compose sample 2025-01-01 14:28:27 +05:30
output.png React - Laravel - MySQL Compose sample 2025-01-01 14:28:27 +05:30
README.md React - Laravel - MySQL Compose sample 2025-01-01 14:28:27 +05:30

Compose sample application

React(Vite) application with a Laravel backend and a MySQL database

Project structure:

.
├── backend
│   ├── ...
│   └── Dockerfile
├── db
│   └── password.txt
├── compose.yaml
├── frontend
│   ├── ...
│   └── Dockerfile
└── README.md

compose.yaml

services:
  backend:
    build: backend
    ...
  db:
    image: mysql:lts
    ports:
      - 8000:80
    ...
  frontend:
    build: frontend
    ports:
      - 3000:3000
    ...

The compose file defines an application with three services frontend, backend and db. When deploying the application, docker compose maps port 3000 of the frontend service container to port 3000 of the host and port 80 of the backend service container to port 8000 of the host as specified in the file. Make sure the ports 3000 and 8000 on the host are not already being in use.

Deploy with docker compose

$ docker compose up -d
✔ Network react-laravel-mysql_laravel-mariadb  Created    0.1s
✔ Network react-laravel-mysql_vite-laravel     Created    0.1s
✔ Container react-laravel-mysql-db-1           Healthy    7.7s
✔ Container react-laravel-mysql-backend-1      Started    8.4s
✔ Container react-laravel-mysql-frontend-1     Started    8.7s

Expected result

Listing containers must show three containers running and the port mapping as below:

$ docker ps
CONTAINER ID   IMAGE                          COMMAND                  CREATED         STATUS                   PORTS                                         NAMES
c842d6bec933   react-laravel-mysql-frontend   "docker-entrypoint.s…"   4 minutes ago   Up 4 minutes             3306/tcp, 0.0.0.0:3000->3000/tcp, 33060/tcp   react-laravel-mysql-frontend-1
c84c2a303e91   react-laravel-mysql-backend    "/usr/local/bin/entr…"   4 minutes ago   Up 4 minutes             0.0.0.0:8000->80/tcp                          react-laravel-mysql-backend-1
44f8a005982e   mysql:lts                      "docker-entrypoint.s…"   4 minutes ago   Up 4 minutes (healthy)   3306/tcp, 33060/tcp                           react-laravel-mysql-db-1

After the application starts, navigate to http://localhost:3000 in your web browser to see this React home page. page

Stop and remove the containers

$ docker compose down
✔ Container react-laravel-mysql-frontend-1     Removed    0.8s
✔ Container react-laravel-mysql-backend-1      Removed    11.3s
✔ Container react-laravel-mysql-db-1           Removed    3.2s
✔ Network react-laravel-mysql_vite-laravel     Removed    0.8s
✔ Network react-laravel-mysql_laravel-mariadb  Removed    0.5s