Attempt #2 to auto compile MongoDB into the build to exclude it from the compose.
This commit is contained in:
@@ -14,8 +14,15 @@ RUN npm install
|
|||||||
COPY src/backend/ ./src/backend/
|
COPY src/backend/ ./src/backend/
|
||||||
|
|
||||||
# Stage 3: Final production image
|
# Stage 3: Final production image
|
||||||
FROM node:18-alpine
|
FROM mongo:5
|
||||||
RUN apk add --no-cache nginx mongodb~=5
|
# Install Node.js
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
curl \
|
||||||
|
nginx \
|
||||||
|
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
|
||||||
|
&& apt-get install -y nodejs \
|
||||||
|
&& apt-get clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Configure nginx
|
# Configure nginx
|
||||||
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
COPY docker/nginx.conf /etc/nginx/nginx.conf
|
||||||
@@ -25,20 +32,13 @@ COPY --from=frontend-builder /app/dist /usr/share/nginx/html
|
|||||||
COPY --from=backend-builder /app/node_modules ./node_modules
|
COPY --from=backend-builder /app/node_modules ./node_modules
|
||||||
COPY --from=backend-builder /app/src/backend ./src/backend
|
COPY --from=backend-builder /app/src/backend ./src/backend
|
||||||
|
|
||||||
# Create persistent directories for MongoDB and nginx
|
# Create directories for nginx
|
||||||
RUN mkdir -p /usr/local/mongodb/data/db && \
|
RUN mkdir -p /var/log/nginx && \
|
||||||
mkdir -p /var/log/nginx && \
|
|
||||||
mkdir -p /var/lib/nginx && \
|
mkdir -p /var/lib/nginx && \
|
||||||
mkdir -p /var/log/mongodb && \
|
chown -R www-data:www-data /var/log/nginx /var/lib/nginx
|
||||||
chown -R nginx:nginx /var/log/nginx /var/lib/nginx && \
|
|
||||||
chown -R mongodb:mongodb /usr/local/mongodb/data/db /var/log/mongodb
|
|
||||||
|
|
||||||
# Set environment variables
|
# Set environment variables
|
||||||
ENV MONGO_URL=mongodb://localhost:27017/termix \
|
ENV MONGO_URL=mongodb://localhost:27017/termix
|
||||||
MONGODB_DATA_DIR=/usr/local/mongodb/data/db \
|
|
||||||
MONGODB_LOG_DIR=/var/log/mongodb
|
|
||||||
|
|
||||||
VOLUME ["/usr/local/mongodb/data/db"]
|
|
||||||
|
|
||||||
# Expose ports
|
# Expose ports
|
||||||
EXPOSE 8080 8081 8082 27017
|
EXPOSE 8080 8081 8082 27017
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
# Start MongoDB with custom data directory
|
# Start MongoDB
|
||||||
mongod --fork --dbpath $MONGODB_DATA_DIR --logpath $MONGODB_LOG_DIR/mongodb.log
|
mongod --fork --logpath /var/log/mongodb.log
|
||||||
|
|
||||||
# Start nginx
|
# Start nginx
|
||||||
nginx
|
nginx
|
||||||
@@ -12,5 +12,5 @@ node src/backend/ssh.cjs &
|
|||||||
# Start the database service
|
# Start the database service
|
||||||
node src/backend/database.cjs &
|
node src/backend/database.cjs &
|
||||||
|
|
||||||
# Keep the container running
|
# Keep the container running and show MongoDB logs
|
||||||
tail -f /dev/null
|
tail -f /var/log/mongodb.log
|
||||||
Reference in New Issue
Block a user