Solutions

All server and microservices related solutions Windows and Linux

Dockerfile For MongoDB

Docker-file For MongoDB

Docker-file For MongoDB. This code will help you understand and write a docker file for MongoDB. The base image for this file is Ubuntu 20.04. We can find more code to my git-hub account click on this Link.

####################################

FROM ubuntu:latest
RUN apt-get update && apt-get install libcurl4 openssl liblzma5 wget gnupg -y
RUN wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-5.0.2.tgz
RUN tar -zxvf mongodb-linux-x86_64-ubuntu2004-5.0.2.tgz
RUN cp mongodb-linux-x86_64-ubuntu2004-5.0.2/bin/* /usr/local/bin/
RUN mkdir -p /var/lib/mongo \
&& mkdir -p /var/log/mongodb
RUN echo "security:" > /etc/mongod.conf \
&& echo " authorization: \"enabled\"" >> /etc/mongod.conf
RUN wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | apt-key add - \
&& echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-5.0.list \
&& apt-get update \
&& apt-get install -y mongodb-mongosh

VOLUME /var/lib/mongo
EXPOSE 27017

ENV DBUSER $DBUSER
ENV DBPASS $DBPASS

ENTRYPOINT mongod --config /etc/mongod.conf --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --bind_ip_all --fork \
&& mongo admin --eval "db.createUser({ user : '$DBUSER', pwd : '$DBPASS', roles : [{ role: 'userAdminAnyDatabase', db: 'admin'}, 'readWriteAnyDatabase']});" \
&& mongosh

####################################