Running Laravel on Docker is really easy with Kool

dbpolito

Daniel Polito

Posted on June 22, 2021

Running Laravel on Docker is really easy with Kool

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Cache

? What cache service do you want to use  [Use arrows to move, type to filter]
> Redis 6.0
  Memcached 1.6
  none
Enter fullscreen mode Exit fullscreen mode

Package Manager

? What javascript package manager do you want to use  [Use arrows to move, type to filter]
  npm
> yarn
Enter fullscreen mode Exit fullscreen mode

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.

kool preset laravel - output

Move into your new Laravel project:

$ cd my-project
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

PostgreSQL 13.0

-DB_CONNECTION=mysql
+DB_CONNECTION=pgsql

-DB_HOST=127.0.0.1
+DB_HOST=database

-DB_PORT=3306
+DB_PORT=5432
Enter fullscreen mode Exit fullscreen mode

Cache Services

Redis

-REDIS_HOST=127.0.0.1
+REDIS_HOST=cache
Enter fullscreen mode Exit fullscreen mode

Memcached

-MEMCACHED_HOST=127.0.0.1
+MEMCACHED_HOST=cache
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

kool laravel welcome screen

Dive Deeper

GitHub logo kool-dev / kool

From local development to the cloud: web apps development with containers made easy.

kool - cloud native dev tool

Go Report Card codecov Docker Hub Golang CI Lint Maintainability Join Slack Kool community Awesome

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.

Learn more at kool.dev.

Installation

Requirements: Kool is powered by…




💖 💪 🙅 🚩
dbpolito
Daniel Polito

Posted on June 22, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related