forked from noxious/server
Added MySQL to dockerfile
This commit is contained in:
parent
f0c0456121
commit
67a4c6763b
22
Dockerfile
22
Dockerfile
@ -1,8 +1,11 @@
|
|||||||
# Use the official Node.js 22.4.1 image
|
# Use the official Node.js 22.4.1 image
|
||||||
FROM node:22.4.1-alpine
|
FROM node:22.4.1-alpine
|
||||||
|
|
||||||
# Install Redis and tmux
|
# Install Redis, MySQL, and tmux
|
||||||
RUN apk add --no-cache redis tmux
|
RUN apk add --no-cache redis mysql mysql-client tmux && \
|
||||||
|
mkdir -p /run/mysqld && \
|
||||||
|
chown -R mysql:mysql /run/mysqld && \
|
||||||
|
mysql_install_db --user=mysql --datadir=/var/lib/mysql
|
||||||
|
|
||||||
# Set the working directory in the container
|
# Set the working directory in the container
|
||||||
WORKDIR /usr/src/
|
WORKDIR /usr/src/
|
||||||
@ -13,11 +16,8 @@ COPY package*.json ./
|
|||||||
# Install application dependencies
|
# Install application dependencies
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
# Copy prisma schema
|
# Import migrations
|
||||||
COPY prisma ./prisma/
|
RUN npx mikro-orm migration:up
|
||||||
|
|
||||||
# Generate Prisma client
|
|
||||||
RUN npx prisma generate
|
|
||||||
|
|
||||||
# Copy the rest of your application code to the container
|
# Copy the rest of your application code to the container
|
||||||
COPY . .
|
COPY . .
|
||||||
@ -25,12 +25,14 @@ COPY . .
|
|||||||
# Build the application
|
# Build the application
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Expose the ports your Node.js application and Redis will listen on
|
# Expose the ports your Node.js application, Redis, and MySQL will listen on
|
||||||
EXPOSE 80 6379
|
EXPOSE 80 6379 3306
|
||||||
|
|
||||||
# Create a shell script to run Redis, run migrations, and start the application in a tmux session
|
# Create a shell script to run Redis, MySQL, run migrations, and start the application in a tmux session
|
||||||
RUN echo '#!/bin/sh' > /usr/src/start.sh && \
|
RUN echo '#!/bin/sh' > /usr/src/start.sh && \
|
||||||
echo 'redis-server --daemonize yes' >> /usr/src/start.sh && \
|
echo 'redis-server --daemonize yes' >> /usr/src/start.sh && \
|
||||||
|
echo 'mysqld --user=mysql --datadir=/var/lib/mysql &' >> /usr/src/start.sh && \
|
||||||
|
echo 'sleep 10' >> /usr/src/start.sh && \
|
||||||
echo 'npx prisma migrate deploy' >> /usr/src/start.sh && \
|
echo 'npx prisma migrate deploy' >> /usr/src/start.sh && \
|
||||||
echo 'tmux new-session -d -s nodeapp "node dist/server.js"' >> /usr/src/start.sh && \
|
echo 'tmux new-session -d -s nodeapp "node dist/server.js"' >> /usr/src/start.sh && \
|
||||||
echo 'echo "App is running in tmux session. Attach with: tmux attach-session -t nodeapp"' >> /usr/src/start.sh && \
|
echo 'echo "App is running in tmux session. Attach with: tmux attach-session -t nodeapp"' >> /usr/src/start.sh && \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user