Docker Compose Laravel Setup

User
version: '3.8'

services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: laravel_app
volumes:
– .:/var/www/html
networks:
– laravel_network
depends_on:
– db
ports:
– "8080:80" # Change this to the desired host port

db:
image: mysql:8.0
container_name: laravel_db
restart: always
environment:
MYSQL_DATABASE: laravel
MYSQL_USER: laravel
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: rootpassword
volumes:
– db_data:/var/lib/mysql
– ./init-scripts:/docker-entrypoint-initdb.d
networks:
– laravel_network

adminer:
image: adminer
container_name: adminer
restart: always
ports:
– "8081:8080" # Change this to the desired host port for Adminer
networks:
– laravel_network

networks:
laravel_network:
driver: bridge

volumes:
db_data:
we are using Interia View for frontend with laravel

Assistant
User is using Interia View for the frontend with Laravel in their application.
Assistant
Your `docker-compose.yml` file looks well-structured for your Laravel application with Inertia.js. Here’s a brief overview of your setup:

1. **App Service**:
– Builds from the provided `Dockerfile`.
– Uses a volume to sync your local files with the container, which is helpful for development.
– Depends on the `db` service to ensure the database is available before the app starts.
– Maps port 8080 on the host to port 80 in the container for accessing the Laravel app.

2. **Database Service**:
– Uses MySQL 8.0.
– Environment variables set up for the database name, user, and passwords.
– Initializes the database with any scripts in the `./init-scripts` directory.
– Uses a volume to persist data.

3. **Adminer Service**:
– Provides a web interface for managing the MySQL database.
– Maps port 8081 on the host to port 8080 in the container.

4. **Network**:
– A custom bridge network named `laravel_network` is created to allow the services to communicate with each other.

### Suggestions
– Make sure your `Dockerfile` is set up to install all necessary dependencies for Laravel and Inertia.js.
– If you have specific npm packages or build steps for your frontend, consider adding those to the Dockerfile or managing them via a separate service.
– Regularly backup your `db_data` volume to prevent data loss.

If you have any specific questions or need help with further configurations, feel free to ask!

Leave a Comment

Your email address will not be published. Required fields are marked *