Skip to content

Commit

Permalink
Update Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
kallyas authored Aug 26, 2023
1 parent 767647f commit da8d9fa
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# Use the official Debian Buster Slim image as the base image
FROM debian:buster-slim
# Use the official Node.js Alpine image as the base image
FROM node:alpine

# Set the working directory in the container
WORKDIR /app

# Install essential packages
RUN apt-get update && apt-get install -y \
python3 \
make \
g++ \
&& rm -rf /var/lib/apt/lists/*
# Install Python and build essentials
RUN apk add --no-cache python3 make g++

# Add the MongoDB repository key
RUN wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | apk add --no-cache gnupg && gpg --import -

# Add the MongoDB repository to APT sources
RUN echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | tee /etc/apt/sources.list.d/mongodb-org-5.0.list
RUN echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" > /etc/apk/repositories

# Install MongoDB and MongoDB tools
RUN apt-get update && apt-get install -y mongodb-org
RUN apk update && apk add --no-cache mongodb-org

# Create a directory for MongoDB data and logs
RUN mkdir -p /data/db /var/log/mongodb
Expand All @@ -26,17 +24,21 @@ RUN mongod --fork --logpath /var/log/mongodb/mongod.log --dbpath /data/db --smal
sleep 5 && \
mongo admin --eval "db.createUser({ user: 'admin', pwd: 'password', roles: [ 'root' ] });"

# Install Node.js and npm
RUN apt-get update && apt-get install -y nodejs npm
# Install OpenRC, which is used to manage system services (Alpine Linux uses OpenRC)
RUN apk add --no-cache openrc

# Enable MongoDB to start at boot
RUN rc-update add mongodb default

# Expose the port that your Node.js Express app listens on (e.g., 3000)
EXPOSE 5000

# Install OpenRC, which is used to manage system services (Debian also uses systemd)
RUN apt-get update && apt-get install -y systemd
# Install Node.js packages and your application
COPY server/package.json server/package-lock.json ./
RUN npm install --production

# Enable MongoDB to start at boot
RUN systemctl enable mongod
# Copy the rest of your application code
COPY . .

# Start MongoDB and your server
CMD systemctl start mongod && node src/index.js
CMD rc-service mongodb start && node src/index.js

0 comments on commit da8d9fa

Please sign in to comment.