Add MongoDB integration and configure Docker container to publish app on port 8084
This commit is contained in:
+35
-17
@@ -11,15 +11,34 @@ RUN npm ci
|
||||
COPY . .
|
||||
RUN VITE_API_URL=$VITE_API_URL npm run build
|
||||
|
||||
# Stage 2: App only (no MariaDB)
|
||||
FROM node:20-alpine
|
||||
# Stage 2: Production environment with Node.js, Nginx, and MongoDB Community Edition
|
||||
FROM node:20-bookworm-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install nginx and curl
|
||||
RUN apk add --no-cache nginx curl bash
|
||||
# Prevent interactive prompts during apt install
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Copy built frontend to nginx
|
||||
# Install dependencies needed for MongoDB repo and general setup
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gnupg \
|
||||
curl \
|
||||
nginx \
|
||||
procps \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Add MongoDB official GPG key and repository (MongoDB 8.0)
|
||||
RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
|
||||
gpg --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg \
|
||||
&& echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/8.0 main" | \
|
||||
tee /etc/apt/sources.list.d/mongodb-org-8.0.list
|
||||
|
||||
# Install MongoDB Community Edition
|
||||
RUN apt-get update && apt-get install -y \
|
||||
mongodb-org \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy built frontend to nginx html folder
|
||||
COPY --from=builder /build/dist /usr/share/nginx/html
|
||||
|
||||
# Copy server files
|
||||
@@ -28,24 +47,23 @@ RUN cd ./server && npm ci
|
||||
|
||||
COPY server/ ./server/
|
||||
|
||||
# Copy nginx config
|
||||
COPY nginx.conf /etc/nginx/http.d/default.conf
|
||||
# Configure Nginx for Debian
|
||||
RUN rm -f /etc/nginx/sites-enabled/default
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Create directories
|
||||
RUN mkdir -p /run/nginx
|
||||
# Create MongoDB data and run directories with correct permissions
|
||||
RUN mkdir -p /data/db /var/log/mongodb /var/run/mongodb && \
|
||||
chown -R mongodb:mongodb /data/db /var/log/mongodb /var/run/mongodb
|
||||
|
||||
# Copy entrypoint
|
||||
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
||||
RUN chmod +x /docker-entrypoint.sh
|
||||
|
||||
EXPOSE 80 4000
|
||||
# ONLY expose port 80 (HTTP)
|
||||
EXPOSE 80
|
||||
|
||||
ENV DB_HOST=db
|
||||
ENV DB_PORT=3306
|
||||
ENV DB_USER=hospital
|
||||
ENV DB_PASSWORD=hospital123
|
||||
ENV DB_NAME=hospital
|
||||
ENV ADMIN_DNI=00000000
|
||||
ENV ADMIN_PASSWORD=Admin123!
|
||||
ENV ADMIN_DNI=35242633
|
||||
ENV ADMIN_PASSWORD=admin123
|
||||
|
||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||
|
||||
Reference in New Issue
Block a user