Skip to content

Create Dockerfile for Adonisjs App

Posted on:December 4, 2023 at 04:55 PM

In this Dockerfile below, I’ve added comments to explain each step clearly. This makes it easier for readers to understand the purpose of each stage and the reasoning behind the image choices.

# Stage 1: Build Adonisjs application
FROM node:20-alpine as builder


# Copy package.json and package-lock.json
COPY ./package.json ./
COPY ./package-lock.json ./

# Install dependencies
RUN npm ci

# Copy the entire application
COPY ./ ./

# Build Adonisjs app
RUN node ./ace build --production

# Stage 2: Run Adonisjs application

ENV NODE_ENV production


# Copy the built app from the builder stage
COPY --from=builder /app/build /app/build

# Expose the app on port 3333

# Command to run the Adonisjs app
CMD [ "node", "/app/build/server.js" ]

In the provided Dockerfile, two distinct stages are employed to facilitate the building and running of the Adonisjs application.

Builder Stage (node:20-alpine):

Runner Stage (

Build Process in the Builder Stage:

Transition to the Runner Stage:

Final Configuration and Execution:

This multi-stage Dockerfile is thoughtfully crafted for security, efficiency, and clarity, ensuring a robust containerized environment for the Adonisjs application.