A complete Laravel, PHP Development environment that is very similar to production environment.
Docker Compose based Laravel development environment with individual App (Laravel app), Nginx, Database (MySQL), Queue, Scheduler, Redis services.
Clone the repo at your development machine. Go to your Laravel Docker directory. Then Run this
sh install
A bash script will download latest Laravel zip and then unzip the Laravel project into the app
directory.
To update Laravel version before installaiton, edit the install
file in root directory.
Run this to build your docker containers for each services (app, database, queue, scheduler, redis).
docker-compose build
docker-compose up
docker-compose up -d
To install Laravel, generate app key and run migrations, you need to ssh to your app container service. To ssh to your app container, run this.
docker-compose exec app sh
This will take you to /var/www/app
path inside your app
service container. Now you can run your composer install
and other Laravel or PHP specific commands there.
To ssh into other containers, replace the app
with other container name as scheduler
, queue
. e.g.
docker-compose exec queue sh
docker-compose stop
If you want to change, enable/disable any PHP settings, you can change them in ./docker/config/php/php-ini-development.ini
file and then build
and up
the container again.
MySQL username, password can be changed from docker-compose.yml
file. Fin the environment
section under mysql
. Change the value and build the mysql image again with docker-compose build mysql
.
environment:
MYSQL_DATABASE: app
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: admin
MYSQL_PASSWORD: secret
After you change the value and build, you need to restart the mysql service docker-compose up mysql
to make it affective.
If you want to change Nginx web host configurations, you can find the file at ./docker/images/web/sites/default.dev.conf
This Laravel-docker-app leverage the power of docker volume
and store some the docker container data at your host machine. Here is the details of folder structure and what data it contain:
./docker/data/mysql
contain mysql database files./docker/data/redis
contain redis database file./docker/data/web
contain nginx webserver logs
host: 0.0.0.0
username: root
password: root
port: 33066
At the moment, there are many other Laravel Docker github repo or packages available, so why this new package again? Here I'll list few of my points:
- This docker app images is based on
alpine
based PHP image, which makes it very light weight. - This is built on service based architecture. Usually for Laravel application, there should be
Queue
andcron
running on behind. In this system, you can runQueue
,Scheduler
container separately and Queue will listen to a separateRedis
database. - It's the most compatible with production environment. Very easily this can be converted to a production grade, scalable service.
You can find your site running at http://localhost