This guide provides a detailed setup for a PHP Laravel environment using Docker, Apache, Ubuntu, and MongoDB. The Docker Compose configuration defines services for the application and MongoDB, allowing for seamless development and testing.
services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: petra_devs
ports:
- "80:80"
- "443:443"
extra_hosts:
- "petradevs.org:127.0.0.1"
environment:
- VIRTUAL_HOST=petradevs.org
restart: unless-stopped
tty: true
volumes:
- ./:/var/www/html/petradevs
- ./storage/logs:/var/www/html/petradevs/storage/logs
links:
- mongodb
networks:
- laravel_network
mongodb:
image: mongodb/mongodb-community-server:latest
container_name: mongodb
restart: unless-stopped
tty: true
volumes:
- mongodb_data:/data/db
ports:
- '27017:27017'
volumes:
mongodb_data:
driver: local
networks:
laravel_network:
driver: bridge
The Docker Compose file defines two services: app
and mongodb
.
app
service builds from the Dockerfile in the current context, sets environment variables, maps ports, and connects to the MongoDB service.mongodb
service uses the latest MongoDB image, maps the MongoDB port, and sets up a persistent volume for data storage.For detailed instructions on setting up the Dockerfile for a PHP development environment with Apache and Ubuntu, refer to the internal link:
Dockerfile Setup: PHP Development Environment with Apache and Ubuntu
To access the local MongoDB instance from within the Docker container, use the following environment variable:
DB_MONGO_DSN=mongodb://host.docker.internal:27017
This configuration allows the application to connect to the MongoDB instance running on the host machine.
For more information on using MongoDB with PHP and Laravel, refer to the official MongoDB documentation:
MongoDB PHP Laravel Documentation
This guide covers the setup of a PHP development environment using Docker, including configuration for Apache, Ubuntu, and MongoDB. By following these steps, you can create a robust and isolated development environment.
Published By: Krishanu Jadiya
Updated at: 2024-07-20 00:31:27