Ready made development environment for Laravel 6.x using docker-compose
GPL-3.0 License
Ready made development environment for Laravel 6.x using docker-compose.
Don't spent hours managing dependencies anymore. Just docker-compose and git - your laravel project will be up and running in minutes!
The environment is composed with the following services -
I am assuming you have basic idea about how to work with git, docker and composer based PHP projects. Otherwise, following the steps may not be easy for you.
You can clone it anywhere in your local machine or download as zip file.
git clone https://github.com/ajaxray/docker-compose-laravel.git /tmp/docker-compose-laravel
If you want to try with fresh Laravel project, check "Starting with fresh Laravel" below in Notes section before proceeding to the next step.
Now, copy docker-compose.yml
file and docker
directory to project root of your laravel application.
cp -vr /tmp/docker-compose-laravel/docker* /path/to/my-project/
cd /path/to/my-project/
.env
variablesEdit the .env
file in project root and set the following values:
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=appuser
DB_PASSWORD=123456
MAIL_HOST=mailhog
MAIL_PORT=1025
Alternatively you may update parameters in docker-compose.yml
file and set .env
parameters accordingly.
Start containers from project root directory
docker-compose up -d
# Check service status
docker-compose ps
If everything went OK, you should see something like this -
That means your Development environment is ready! But we have one more step before checking the live application.
These are generic steps to prepare any Laravel application, not specific to this Docker setup. But you need to run them from inside appropriate container. (You may ignore any of the following commands if not required for your project.)
docker-compose exec app composer install --no-interaction --no-suggest --no-progress --prefer-dist
docker-compose exec app php artisan key:generate
docker-compose exec app php artisan migrate
docker-compose exec app php artisan db:seed
# Required for Vue.js and laravel-mix
docker-compose exec app npm install
docker-compose exec app npm run dev
# Cache configuration. Recommended for production environment
docker-compose exec app php artisan config:cache
Good News - Your project is live by now!
Check it here:
The information above can be different if you've modified parameter values in docker-compose.yml
.
Starting with fresh Laravel
If you have not started (or cloned) the project yet, you can start a latest Laravel project using ONLY git (no other dependencies):
git clone https://github.com/laravel/laravel.git my-project
cd my-project
cp .env.example .env
Updating PHP configuration
docker/php/local.ini
is being loaded with PHP ini of app
service. So, if you need to modify/add any ini value, you can use this file.
Updating Nginx configuration
All config files under docker/nginx/conf.d/
will be loaded by Nginx. You can modify/add files here to modify Nginx config.
The application hosting is defined in app.conf
of this directory. Check it to know log file locations and other configurations.
Updating Database configuration
docker/mysql/my.cnf
is being loaded with database configuration of db
service. So, if you need to modify/add any configuration, use it.
Connecting database from other database client
To avoid conflict with local MySQL (if any), database port mapped to 33061
for localhost.
That means, if you want to connect the database inside container from a database client, you have to use 33061
port.
Selecting Image library
ImageMagick and ghostscript is enabled by default. If you prefer GD instead, comment out ImageMagick section and uncomment GD section in docker/php/Dockerfile
Add/Remove/Modify services of docker-compose
If you need to add/remove/modify any service anytime later (after docker-compose up
), feel free to do.
Just remember to run the following commands from project directory to apply your changes -
docker-compose down
docker-compose up --force-recreate --build -d
docker image prune -f