Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install mongodb database tools in a Dockerfile?

Tags:

docker

mongodb

Pretty much the question. Here's what I have currently:

FROM node:15 as server
WORKDIR /app
ENV NODE_ENV=production
COPY server/package.json ./
RUN npm install
COPY server/ ./
RUN apt-get update 
RUN apt-get install -y mongo-tools
EXPOSE 5000
CMD ["node", "src/app.js"]

Which does work however mongo-tools is a really outdated version of the tools and is not fit for my pusposes.

Mongo Docs has instructions for how to install the newer mongodb-database-tools on linux/windows/macos but I can't figure out how to get it to work in a DockerFile.

For anyone wondering, I'm trying to get a node-cron to periodically call mongodump on a mongodb atlas database.

Any help is appreciated :)

like image 861
maxout Avatar asked Nov 06 '25 10:11

maxout


2 Answers

you can download newer version of the tools and install it, just like you do on linux host

example Dockerfile like below:

FROM node:15 as server
WORKDIR /app
ENV NODE_ENV=production
RUN wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-debian92-x86_64-100.3.1.deb && \
    apt install ./mongodb-database-tools-*.deb && \
    rm -f mongodb-database-tools-*.deb
COPY server/package.json ./
RUN npm install
COPY server/ ./
EXPOSE 5000
CMD ["node", "src/app.js"]
like image 71
fancy Avatar answered Nov 08 '25 01:11

fancy


For those using node:alpine this is how I did it:

FROM node:18.17.1-alpine3.18

WORKDIR /usr/local/app

RUN apk --no-cache add mongodb-tools

...
like image 37
Miko Chu Avatar answered Nov 08 '25 01:11

Miko Chu