This guide explains how to set up a PostgreSQL database for an AdonisJS project using Docker. The AdonisJS backend will run manually via the console, and the database will be managed by Docker.
-
Docker and Docker Compose installed on your system.
-
.env
file configured in thebackend/
directory with the following variables:TZ=UTC PORT=3333 HOST=localhost LOG_LEVEL=info APP_KEY=your_app_key NODE_ENV=development DB_HOST=127.0.0.1 DB_PORT=5432 DB_USER=root DB_PASSWORD=root DB_DATABASE=app
To start the PostgreSQL container, run inside backend/
directory:
docker-compose up -d db
This command will:
- Start the PostgreSQL database service based on the configuration in
docker-compose.yml
. - Set up a database with the name, user, and password defined in your
.env
.
If your AdonisJS application requires migrations, you can apply them manually using the following command after starting the database:
node ace migration:run
With the database running, you can start your AdonisJS server manually from the backend/
directory:
node ace serve --hmr
or if you prefer
npm run dev
Your AdonisJS application should now be available at http://localhost:3333
.
To stop the PostgreSQL container:
docker-compose down
This command will stop the database but keep the data in the my_dbdata
volume for persistence across restarts.