This repository helps you set up your Laravel projects using Docker, even if you are not familiar with Docker.
- laravel app
- nginx web server
- mysql database
first, clone the repository:
git clone https://github.com/devsoli/docker-laravel.git
cd docker-laravel
copy the .env.example file to .env:
cp .env.example .env
config database connection in .env file:
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=password
docker-compose build app
to start the services, run:
docker-compose up -d
This command will run the Docker containers in the background.
Enter the app container and install Composer dependencies:
docker-compose exec app composer install
Set the application key:
docker-compose exec app php artisan key:generate
Migrate the database:
docker-compose exec app php artisan migrate
After successfully running the above commands, your Laravel application should be accessible at http://localhost.
- View logs:
docker-compose logs -f
- Stop services:
docker-compose down
- Access the container:
docker-compose exec app bash
- Ports are already in use: Make sure that ports 80 and 3306 are not being used by another service.
- Permissions: If you encounter file permission issues, try the following commands:
sudo chown -R $USER:$USER .
If you encounter any issues or have any questions, please open a new issue in the Issues section.
I hope this guide helps you easily set up your Laravel projects with Docker.