I'm trying to Dockerize Adonis following the tutorial of Adonis and the base installation :
https://v5-docs.adonisjs.com/cookbooks/dockerizing-adonis
https://docs.adonisjs.com/guides/getting-started/installation
I'm using the basic starter :
npm init adonisjs@latest hello-world -- --db=mysql --kit=api
The dockerfile is the same as the guide, same for the docker compose, i just don't use postgres or redis
I started a mariadb in my docker to try the app without dockerizing it, it work fine but if i try to start it using docker compose i have the SyntaxError :
file:///home/node/app/ace.js:22
import { register } from 'node:module'
^^^^^^^^
SyntaxError: The requested module 'node:module' does not provide an export named 'register'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:181:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)
docker-compose.yml
services:
mariadb:
image: mariadb:10.6
container_name: mariadb
volumes:
- "._mysql_data_dir/:/var/lib/mysql"
ports:
- "3306:3306"
environment:
- MARIADB_USER=xxx
- MARIADB_PASSWORD=xxx
- MARIADB_DATABASE=xxx
- MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=true
restart: always
adonis_app:
container_name: adonis_app
restart: always
build:
context: .
target: dependencies
ports:
- ${PORT}:${PORT}
- 9229:9229
env_file:
- .env
volumes:
- ./:/home/node/app
# Uncomment the below line if you developing on MacOS
#- /home/node/app/node_modules
command: dumb-init node ace serve --watch --node-args="--inspect=0.0.0.0"
Dockerfile
ARG NODE_IMAGE=node:16.13.1-alpine
FROM $NODE_IMAGE AS base
RUN apk --no-cache add dumb-init
RUN mkdir -p /home/node/app && chown node:node /home/node/app
WORKDIR /home/node/app
USER node
RUN mkdir tmp
FROM base AS dependencies
COPY --chown=node:node ./package*.json ./
RUN npm ci
COPY --chown=node:node . .
FROM dependencies AS build
RUN node ace build --production
FROM base AS production
ENV NODE_ENV=production
ENV PORT=$PORT
ENV HOST=0.0.0.0
COPY --chown=node:node ./package*.json ./
RUN npm ci --production
COPY --chown=node:node --from=build /home/node/app/build .
EXPOSE $PORT
CMD [ "dumb-init", "node", "server.js" ]
Node version : v21.6.1
I have the same error on Ubuntu 22.04 and Windows 10
Am i missing something ?
volumes:block in the Compose file, otherwise pretty much everything in the Dockerfile gets ignored.)