-
Copy the
dockerdirectory to your Laravel project's root directory. -
Copy the
docker-compose.ymlto your Laravel project's root directory. -
Add
/database/mysqlto your project's.gitignorefile so that git won't track your database. -
Configure the Laravel
.envfile.-
set
DB_DATABASE,DB_USERNAME, andDB_PASSWORD. When the mysql container is started, it will create this database, if it is not already present. Database files will be located in/database/mysqlunder the project root.DB_DATABASE=myappdb DB_USERNAME=admin DB_PASSWORD=secretpasswordtext -
Set
DB_HOSTandREDIS_hostto their respective service names found indocker-compose.yml.DB_HOST=mysql REDIS_HOST=redis -
Set all of the following to
redis:BROADCAST_DRIVER=redis CACHE_DRIVER=redis SESSION_DRIVER=redis QUEUE_DRIVER=redis -
See the ADDITIONAL ENVIRONMENT VARIABLES section below for other optional settings.
-
-
Any SQL commands you place into
docker/mysql/docker-entrypoint-initdb.d/createdb.sqlwill be executed upon creation as well. This is a good place to have yourdbname_testingdatabase created (optionally used by phpunit.xml for testing). There are examples in that file. -
Run
docker-compose up -d --buildto start your project. This should be executed from the Laravel project's root directory.
You can now visit your application in a browser at the WEB_PORT specified (8010 by default)
ADDITIONAL ENVIRONMENT VARIABLES
The following are environment variables that you can include in your Laravel .env file to control certain aspects of the build process and the operation of your application. If these variables are not added to Laravel's .env file, the DEFAULT is used.
| VARIABLE | DEFAULT | DESCRIPTION |
|---|---|---|
| WEB_PORT | 8010 | The web interface port |
| PORTAINER_PORT | 9001 | The Portainer port |
| BASE_TAG | laravel | The tag used for the repository name when building images. This needs to be all lowercase, no spaces |
| TZ | America/Chicago | The timezone used by the mysql build process |
Here are examples of how each of these environment variables would be set in the .env file:
WEB_PORT=8088
PORTAINER_PORT=9002
BASE_TAG=mycoolthing
TZ=America/Denver