Creating a new Laravel application with
kool create makes it easy to leverage Docker like nothing else in 3 simple steps. Give it a try!
1. Creating new Laravel application
Requirements: you must have previously installed the
$ kool create laravel my-app
The command above may take a minute or two to run - time for Composer to download all of Laravel vendor dependencies. After finished installing,
kool preset will be automatically executed and the wizard will ask you about how you want to setup your development environment for that project. You will be inquired for:
- PHP version
? What app service do you want to use [Use arrows to move, type to filter] > PHP 7.4 PHP 8.0
? What database service do you want to use [Use arrows to move, type to filter] > MySQL 8.0 MySQL 5.7 PostgreSQL 13.0 none
? What cache service do you want to use [Use arrows to move, type to filter] > Redis 6.0 Memcached 1.6 none
After picking your preferences we will have a fresh installation of Laravel (latest version) in the folder
kool environment almost ready to go!
Next we need to make a few tweaks to default
.env that ships with Laravel. We must change the hosts from localhost to their containers name (accessible from within Docker).
-DB_HOST=127.0.0.1 +DB_HOST=database -DB_USERNAME=root +DB_USERNAME=kool -DB_PASSWORD= +DB_PASSWORD=secret -MEMCACHED_HOST=127.0.0.1 +MEMCACHED_HOST=cache -REDIS_HOST=127.0.0.1 +REDIS_HOST=cache
Pro tip: apply these changes not only to your
.envbut also to
.env.exampleso future clones/other developers will be ready for running it out of the box.
Last step, fire up the local environment:
$ cd my-app/ $ kool start
Note: if you are running
kool startfor the first time, it is possible that Docker will have to download all of the container images that will be used, in that case it can take a few minutes depending on your internet connection.
That is it! After
kool start has finished you can checkout your fresh Laravel installation at http://localhost.
$ kool start Creating network "web_kool_local" with the default driver Creating web_app_1 ... done Creating web_database_1 ... done Creating web_cache_1 ... done