In just 3 simple steps, you can use Kool CLI's kool create
command to start a new Laravel application running in a local Docker environment. Kool is an open source dev tool that makes using Docker for local development a lot easier.
Before you start, if you haven't done so already, you need to install Docker and Kool CLI.
1. Create a new Laravel application
$ kool create laravel my-project
This command may take a minute or two to complete while Composer downloads Laravel's vendor dependencies. After installing Laravel, kool create
automatically runs the kool preset laravel
command, which helps you set up your project's development environment using an interactive wizard.
PHP
? What app service do you want to use [Use arrows to move, type to filter]
> PHP 8.0
PHP 7.4
Database
? What database service do you want to use [Use arrows to move, type to filter]
> MySQL 8.0
MySQL 5.7
MariaDB 10.5
PostgreSQL 13.0
none
Cache
? What cache service do you want to use [Use arrows to move, type to filter]
> Redis 6.0
Memcached 1.6
none
Package Manager
? What javascript package manager do you want to use [Use arrows to move, type to filter]
npm
> yarn
After selecting your preferences, the latest version of Laravel will be installed and ready for you in your my-project
folder, along with your new kool
environment.
Move into your new Laravel project:
$ cd my-project
The kool preset
command auto-generated the following configuration files and added them to your project, which you can modify and extend.
+docker-compose.yml
+kool.yml
2. Update .env.example
Next, we need to make a few tweaks to the default .env.example file that ships with Laravel in order to match the services in your docker-compose.yml file. For example, we need to change the hosts from localhost to the appropriate service container name, which are accessible from within Docker.
Database Services
MySQL 5.7 and 8.0 / MariaDB 10.5
-DB_HOST=127.0.0.1
+DB_HOST=database
PostgreSQL 13.0
-DB_CONNECTION=mysql
+DB_CONNECTION=pgsql
-DB_HOST=127.0.0.1
+DB_HOST=database
-DB_PORT=3306
+DB_PORT=5432
Cache Services
Redis
-REDIS_HOST=127.0.0.1
+REDIS_HOST=cache
Memcached
-MEMCACHED_HOST=127.0.0.1
+MEMCACHED_HOST=cache
3. Run kool run setup
Now, spin up your local environment for the first time using the setup
script in your kool.yml file:
$ kool run setup
Note: if you're running this command for the first time, Docker may need to download all the container images that are being used, which can take a few minutes, depending on your internet connection.
That's it!
After kool run setup
has finished, you can access your new Laravel app at http://localhost.
$ kool run setup
Creating network "my-project_kool_local" with the default driver
Creating volume "my-project_database" with default driver
Creating volume "my-project_cache" with default driver
Creating my-project_cache_1 ... done
Creating my-project_app_1 ... done
Creating my-project_database_1 ... done
Dive Deeper
- Read the docs for our Laravel Preset to learn more about using Kool with Laravel.
- Go to kool.dev to learn more about the Kool open source project.
kool-dev / kool
From local development to the cloud: web apps development with containers made easy.
About kool
Kool is a CLI tool that brings the complexities of modern software development environments down to earth - making these environments lightweight, fast and reproducible. It reduces the complexity and learning curve of Docker containers for local environments, and offers a simplified interface for using Kubernetes to deploy staging and production environments to the cloud.
Kool gets your local development environment up and running easily and quickly, so you have more time to build a great application. When the time is right, you can then use Kool.dev Cloud to deploy and share your work with the world!
Kool is suitable for solo developers and teams of all sizes. It provides a hassle-free way to handle the Docker basics and immediately start using containers for development, while simultaneously guaranteeing no loss of control over more specialized Docker environments.
Installation
Requirements: Kool is powered by…
Top comments (21)
This is pretty cool. Does it work for production or is it manly for local development?
I've been using official Laravel Sail package which does a similar thing for local environments and it's been very good.
The Docker/DockerCompose is meant mostly for local development, although you can (and we have done) just use it in production as well, but that is not advised.
We are in a closed beta phase testing a tool where you can very, very easily deploy your local Docker Compose setup to a Kool.dev managed Kubernetes cluster. It will be as simple as "kool deploy". Stay tuned and follow us here that we soon will be posting more about it.
Please dont take me wrong, had to ask.
You said:
" you can (and we have done) just use it in production as well, but that is not advised"
Why would you do something on production, business, source of incomes, etc.. if you are not recommending it?
I am really confused.
Why is not advised, what Are the reasons? You are using it. Please help me understand Fabricio
Thanks for asking, indeed it came out a little confusing. Let me clarify:
What is not advised is to use the very same Docker Compose structure we use for local development, to a production deployment. We did that in the beginning for how easy it was... But when we talk about production we need to think about scaling/monitoring/observability/etc...
That is why for production we parse the Docker Compose local env to a Kubernetes namespace, where we are more provisioned and prepared to keep good care of production grade containers.
So Docker Compose is great for running a set of containers together, which helps a lot development of container based applications. But when we talk production, we will use those very same containers, but in a different orchestrator, to help us with the requirements of a production deployment.
And just to add to it - Kool CLI will help you all the way for local development in multiple languages/microservices/frameworks...
To move all that to production, we are cooking what we call Kool Cloud for helping making any Docker Compose based local environment deployable to a Kubernetes cluster. That is the coming soon/stay tuned part of my initial answer all about.
Laravel Sail is indeed great, we do have some differences so i would love if you could try and give us your feedback, we also support different stacks (frameworks, languages) with the very same UX.
We already support / use kool images in production, if you take a look at our image: github.com/kool-dev/docker-php
As Fabricio said, we are also working on a premium feature called Kool Cloud but we plan to have proper documentation on how to use Kool on production with Docker, which is done but not documented yet.
If you're interested in learning more about it, please join our slack at kool.dev/slack and we can help you get started.
I've been using kool for months. It's an amazing tool to increase performance and security, it makes you life so much more easier =D
It fits perfectly in my project that uses: NodeJs(adonis) and ReactJs
Thanks for this article.
Pretty cool package, have used it several times for laravel and so far so good
I've been working with Kool since the early stages and loved it from the beginning! :)
Such a great tool to simplify what a developer needs, and it is in constant development & improvement.
Highly recommend it!
Very Informative and useful! Kool is a powerful tool to accelerate development and focus on what matters the most, coding.
I'm using, and this tool increases my productivity so much! Thanks, Kool team!
Does Kool work with WordPress and other PHP frameworks?
Yes! We even have a preset to start a new wordpress project! Check out the doc here: kool.dev/docs/presets/wordpress
In case you wanna drop us a message on Slack, we wanna help more people getting up and running with Docker! kool.dev/slack
It's awesome tool to increase productivity. I don't worry more about the local environment. Perfect for beginners and advanced users.
Also following its development from the beginning and the improvement has been continuous and exponential.
Thanks Kool team!
Can you use this on existing laravel project?
Yes...
We need to improve in our docs, but instead of running
kool create
you will cd into your laravel project and runkool preset laravel
, this will open the wizard and will create the files needed to start using it on your project.The other steps are pretty much the same.