Docker Compose Laravel Setup
October 27, 2024 · AI Conversations
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
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!