Dockerized Adonisjs
Posted on
Dockerfile for production build
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=3333
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" ]
Dockerfile for development build
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
FROM base AS development
ENV NODE_ENV=development
ENV PORT=3333
ENV HOST=0.0.0.0
COPY --chown=node:node ./package*.json ./
RUN npm ci
COPY --chown=node:node --from=build /home/node/app/build .
EXPOSE $PORT
CMD [ "dumb-init", "node", "server.js" ]
Run image using docker-compose
version: '3.8'
services:
myapi:
deploy:
mode: replicated
replicas: 2
image: registry.domain.tld/sumar/myapi:latest
restart: always
environment:
- PORT=
- HOST=
- NODE_ENV=
- APP_KEY=
- DRIVE_DISK=local
- DB_CONNECTION=
- MYSQL_HOST=
- MYSQL_PORT=
- MYSQL_USER=
- MYSQL_PASSWORD=
- MYSQL_DB_NAME=
- REDIS_CONNECTION=local
- REDIS_HOST=
- REDIS_PORT=
- REDIS_PASSWORD=
#volumes:
# - './uploads:/home/node/app/uploads'
networks:
- internal-network
- proxy-network
networks:
internal-network:
external: true
proxy-network:
external: true