From f215ab53dbefa34972f9703083792ff446c3a342 Mon Sep 17 00:00:00 2001 From: Ali Sharafi <47324261+ali-sharafi@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:14:27 +0200 Subject: [PATCH] Add pm2 in dockerfile & restart docker ps on error (#97) --- Dockerfile | 21 +++++++++++---------- docker-compose.yml | 3 ++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5d84ac5..91ec309 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,20 @@ -# syntax=docker/dockerfile:1.3 -FROM node:18-alpine AS builder -COPY --chown=1000:1000 . /fredy +FROM node:18 + WORKDIR /fredy -USER 1000 + +COPY . /fredy + RUN yarn install + +RUN yarn global add pm2 + RUN yarn run prod -FROM node:16-alpine -COPY --from=builder --chown=1000:1000 /fredy /fredy RUN mkdir /db /conf && \ chown 1000:1000 /db /conf && \ chmod 777 -R /db/ && \ ln -s /db /fredy/db && ln -s /conf /fredy/conf + EXPOSE 9998 -USER 1000 -VOLUME [ "/conf", "/db" ] -WORKDIR /fredy -CMD node index.js --no-daemon + +CMD pm2-runtime index.js diff --git a/docker-compose.yml b/docker-compose.yml index 80da407..f6d96f1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.3' +version: '3.8' services: fredy: container_name: fredy @@ -13,3 +13,4 @@ services: - ./db:/db ports: - 9998:9998 + restart: unless-stopped