Docker Environment For Laravel
dockerdirectory to your Laravel project's root directory.
docker-compose.ymlto your Laravel project's root directory.
/database/mysqlto your project's
.gitignorefile so that git won't track your database.
Configure the Laravel
DB_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
REDIS_hostto their respective service names found in
Set all of the following to
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 your
dbname_testingdatabase created (optionally used by phpunit.xml for testing). There are examples in that file.
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.
|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
WEB_PORT=8088 PORTAINER_PORT=9002 BASE_TAG=mycoolthing TZ=America/Denver