Spaces:
Runtime error
Runtime error
anuj
commited on
Commit
·
ef798ec
1
Parent(s):
4f4c931
batfa
Browse files- Dockerfile +9 -10
- start.sh +10 -7
Dockerfile
CHANGED
|
@@ -24,16 +24,18 @@ RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
|
|
| 24 |
&& apt-get update \
|
| 25 |
&& apt-get install -y mongodb-org mongodb-mongosh
|
| 26 |
|
| 27 |
-
# Create
|
| 28 |
-
RUN useradd -M rocketchat && \
|
| 29 |
-
usermod -L rocketchat
|
| 30 |
-
|
| 31 |
-
# Create required directories and set permissions
|
| 32 |
RUN mkdir -p /data/db /opt/Rocket.Chat /var/log && \
|
| 33 |
-
touch /var/log/mongodb.log
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
chmod 777 /var/log/mongodb.log
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# Download and install Rocket.Chat
|
| 38 |
RUN curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz && \
|
| 39 |
tar -xzf /tmp/rocket.chat.tgz -C /opt/Rocket.Chat --strip-components=1 && \
|
|
@@ -54,8 +56,5 @@ EXPOSE 27017 7860
|
|
| 54 |
COPY start.sh /start.sh
|
| 55 |
RUN chmod +x /start.sh
|
| 56 |
|
| 57 |
-
# Switch to non-root user
|
| 58 |
-
USER rocketchat
|
| 59 |
-
|
| 60 |
ENTRYPOINT ["/start.sh"]
|
| 61 |
|
|
|
|
| 24 |
&& apt-get update \
|
| 25 |
&& apt-get install -y mongodb-org mongodb-mongosh
|
| 26 |
|
| 27 |
+
# Create required directories
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
RUN mkdir -p /data/db /opt/Rocket.Chat /var/log && \
|
| 29 |
+
touch /var/log/mongodb.log
|
| 30 |
+
|
| 31 |
+
# Set proper permissions
|
| 32 |
+
RUN chown -R mongodb:mongodb /data/db /var/log/mongodb.log && \
|
| 33 |
chmod 777 /var/log/mongodb.log
|
| 34 |
|
| 35 |
+
# Create rocketchat user
|
| 36 |
+
RUN useradd -M rocketchat && \
|
| 37 |
+
usermod -L rocketchat
|
| 38 |
+
|
| 39 |
# Download and install Rocket.Chat
|
| 40 |
RUN curl -L https://releases.rocket.chat/latest/download -o /tmp/rocket.chat.tgz && \
|
| 41 |
tar -xzf /tmp/rocket.chat.tgz -C /opt/Rocket.Chat --strip-components=1 && \
|
|
|
|
| 56 |
COPY start.sh /start.sh
|
| 57 |
RUN chmod +x /start.sh
|
| 58 |
|
|
|
|
|
|
|
|
|
|
| 59 |
ENTRYPOINT ["/start.sh"]
|
| 60 |
|
start.sh
CHANGED
|
@@ -10,26 +10,29 @@ systemLog:
|
|
| 10 |
path: /var/log/mongodb.log
|
| 11 |
logAppend: true
|
| 12 |
net:
|
| 13 |
-
bindIp:
|
| 14 |
port: 27017
|
| 15 |
replication:
|
| 16 |
replSetName: rs01
|
| 17 |
-
processManagement:
|
| 18 |
-
fork: false
|
| 19 |
EOF
|
| 20 |
|
| 21 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
echo "Starting MongoDB..."
|
| 23 |
mongod --config /tmp/mongod.conf &
|
| 24 |
-
MONGO_PID=$!
|
| 25 |
|
| 26 |
# Wait for MongoDB to be ready
|
| 27 |
echo "Waiting for MongoDB to start..."
|
| 28 |
max_attempts=30
|
| 29 |
attempt=1
|
| 30 |
-
|
|
|
|
| 31 |
if [ $attempt -gt $max_attempts ]; then
|
| 32 |
-
echo "MongoDB failed to start
|
|
|
|
| 33 |
exit 1
|
| 34 |
fi
|
| 35 |
echo "Attempt $attempt of $max_attempts: MongoDB not ready yet..."
|
|
|
|
| 10 |
path: /var/log/mongodb.log
|
| 11 |
logAppend: true
|
| 12 |
net:
|
| 13 |
+
bindIp: 127.0.0.1
|
| 14 |
port: 27017
|
| 15 |
replication:
|
| 16 |
replSetName: rs01
|
|
|
|
|
|
|
| 17 |
EOF
|
| 18 |
|
| 19 |
+
# Ensure proper permissions
|
| 20 |
+
echo "Setting up permissions..."
|
| 21 |
+
chown -R mongodb:mongodb /data/db /var/log/mongodb.log
|
| 22 |
+
|
| 23 |
+
# Start MongoDB
|
| 24 |
echo "Starting MongoDB..."
|
| 25 |
mongod --config /tmp/mongod.conf &
|
|
|
|
| 26 |
|
| 27 |
# Wait for MongoDB to be ready
|
| 28 |
echo "Waiting for MongoDB to start..."
|
| 29 |
max_attempts=30
|
| 30 |
attempt=1
|
| 31 |
+
|
| 32 |
+
while ! mongosh --quiet --eval "db.version()" > /dev/null 2>&1; do
|
| 33 |
if [ $attempt -gt $max_attempts ]; then
|
| 34 |
+
echo "MongoDB failed to start. Showing logs:"
|
| 35 |
+
cat /var/log/mongodb.log
|
| 36 |
exit 1
|
| 37 |
fi
|
| 38 |
echo "Attempt $attempt of $max_attempts: MongoDB not ready yet..."
|