AdonisJs - Presets
Start an AdonisJs Project with Docker in 3 Easy Steps
kool create adonis my-project
- Update .env
kool run setup
Yes, using kool + Docker to create and work on new AdonisJs projects is that easy!
If you haven't done so already, you first need to install Docker and the kool CLI.
Also, make sure you're running the latest version of kool. Run the following command to compare your local version of kool with the latest release, and, if a newer version is available, automatically download and install it.
$ kool self-update
Please note that it helps to have a basic understanding of how Docker and Docker Compose work to use Kool with Docker.
kool create adonis my-project
kool create PRESET FOLDER command to create your new AdonisJs project:
$ kool create adonis my-project
Under the hood, this command will run
adonis new my-project to install the AdonisJs fullstack blueprint.
After installing AdonisJs,
kool create automatically runs the
kool preset adonis command, which helps you easily set up the initial tech stack for your project using an interactive wizard.
Now, move into your new AdonisJs project:
$ cd my-project
kool preset command auto-generated the following configuration files and added them to your project, which you can modify and extend.
Now's a good time to review the docker-compose.yml file and verify the services match the choices you made earlier using the wizard.
2. Update .env
You need to update some default values in AdonisJs' .env file to match the services in your docker-compose.yml file.
We recommend you make the same changes in your .env.example file.
If you selected "none" for database service when answering the preset wizard questions, and you decide to use AdonisJs' default SQLite database, you'll need to install the
sqlite3package and make this change (see "Connect to Docker Database Container" below for more info).
MySQL 5.7 and 8.0
-DB_CONNECTION=sqlite +DB_CONNECTION=mysql -DB_HOST=127.0.0.1 +DB_HOST=database
-DB_CONNECTION=sqlite +DB_CONNECTION=pgsql -DB_HOST=127.0.0.1 +DB_HOST=database -DB_PORT=3306 +DB_PORT=5432
If you added a cache service to docker-compose.yml, you need to add these new environment variables, depending on which service you selected.
kool run setup
Say hello to kool.yml, say goodbye to custom shell scripts!
As mentioned above, the
kool preset command added a kool.yml file to your project. Think of kool.yml as a super easy-to-use task helper. Instead of writing custom shell scripts, add your own scripts to kool.yml (under the
scripts key), and run them with
kool run SCRIPT (e.g.
kool run adonis). You can add your own single line commands (see
adonis below), or add a list of commands that will be executed in sequence (see
To help get you started, kool.yml comes prebuilt with an initial set of scripts (based on the preset), including a script called
setup, which helps you spin up a project for the first time.
scripts: adonis: kool exec app adonis npm: kool exec app npm # or yarn npx: kool exec app npx setup: - kool docker kooldev/node:16 npm install # or yarn install - kool start
Go ahead and run
kool run setup to start your Docker environment and finish setting up your project:
$ kool run setup
As you can see in kool.yml, the
setupscript will do the following in sequence: run
npm installto build your Node packages and dependencies (by spinning up and down a temporary Node container); and then start your Docker environment using docker-compose.yml (which includes a
commandto automatically run
adonis serve --dev).
kool run setup finishes, you should be able to access your new site at http://localhost:3333 and see the AdonisJs "It works!" welcome page. Hooray!
Verify your Docker container is running using the
kool status command:
$ kool status +---------+---------+------------------------+--------------+ | SERVICE | RUNNING | PORTS | STATE | +---------+---------+------------------------+--------------+ | app | Running | 0.0.0.0:3333->3333/tcp | Up 5 seconds | +---------+---------+------------------------+--------------+
kool logs app to see the logs from the running
app container, and confirm the AdonisJs server was started.
kool logsto see the logs from all running containers. Add the
kool logsto follow the logs (i.e.
kool logs -f app).
$ kool logs app Attaching to my-project_app_1 app_1 | app_1 | SERVER STARTED app_1 | > Watching files for changes... app_1 | app_1 | info: serving app on http://0.0.0.0:3333
Run Commands in Docker Containers
kool exec to execute a command inside a running service container:
# kool exec [OPTIONS] SERVICE COMMAND [--] [ARG...] $ kool exec app node -v
kool run adonis --help to execute the
kool exec app adonis --help command in your running
app container and print out information about AdonisJs' commands.
Open Sessions in Docker Containers
Similar to SSH, if you want to open a Bash session in your
app container, run
kool exec app bash, where
app is the name of the service container in docker-compose.yml. If you prefer, you can use
sh instead of
kool exec app sh).
$ kool exec app bash bash-5.1# $ kool exec app sh /app #
Connect to Docker Database Container
You'll need to install the appropriate Node packages to use a database service. For example, to use AdonisJs' default SQLite database, you'll need to add the
sqlite3package by running
kool run npm install sqlite3 --save(or
kool run yarn add sqlite3 --save), after which you can call
kool run adonis migration:runto run migrations (and don't forget to change
databasein your .env file).
If you added a database service, you can easily start a new SQL client session inside your running
database container by executing
kool run mysql (MySQL) or
kool run psql (PostgreSQL) in your terminal. This runs the single-line
psql script included in your kool.yml.
Access Private Repos and Packages in Docker Containers
If you need your
app container to use your local SSH keys to pull private repositories and/or install private packages (which have been added as dependencies in your
package.json file), you can simply add
$HOME/.ssh:/home/kool/.ssh:delegated under the
volumes key of the
app service in your docker-compose.yml file. This maps a
.ssh folder in the container to the
.ssh folder on your host machine.
volumes: - .:/app:delegated + - $HOME/.ssh:/home/kool/.ssh:delegated
When it's time to stop working on the project:
$ kool stop
And when you're ready to start work again:
$ kool start
We have more presets to help you start projects with kool in a standardized way across different frameworks.
Missing a preset? Make a request, or contribute by opening a Pull Request. Go to https://github.com/kool-dev/kool/tree/main/presets and browse the code to learn more about how presets work.