server/Dockerfile
2024-09-30 21:14:19 +02:00

40 lines
1.1 KiB
Docker

# Use the official Node.js 22.4.1 image
FROM node:22.4.1-alpine
# Install Redis and screen
RUN apk add --no-cache redis screen
# Set the working directory in the container
WORKDIR /usr/src/
# Copy package.json and package-lock.json (if available)
COPY package*.json ./
# Install application dependencies
RUN npm install
# Copy prisma schema
COPY prisma ./prisma/
# Generate Prisma client
RUN npx prisma generate
# Copy the rest of your application code to the container
COPY . .
# Build the application
RUN npm run build
# Expose the ports your Node.js application and Redis will listen on
EXPOSE 80 6379
# Create a shell script to run Redis, run migrations, and start the application in a screen session
RUN echo '#!/bin/sh' > /usr/src/start.sh && \
echo 'redis-server --daemonize yes' >> /usr/src/start.sh && \
echo 'npx prisma migrate deploy' >> /usr/src/start.sh && \
echo 'screen -dmS nodeapp node dist/server.js' >> /usr/src/start.sh && \
echo 'exec /bin/sh' >> /usr/src/start.sh && \
chmod +x /usr/src/start.sh
# Use the shell script as the entry point
CMD ["/usr/src/start.sh"]