4

I am using fig to build and run my app within various Docker containers and so-far, so good.

I have a container for my app and a db container with mongo in it.

But now I am trying to connect to the mongo server to seed it with a user and database and I can't find how to install the mongo client.

My app's image is derived from the standard dockerfile/nodejs image and that does not include a mongo client.

Trying RUN mongo just gives an error mongo not found.

All the documentation I've turned up so far relates to how to install the mongo server within a Docker container, and nothing I;ve found so far tells me how to install the mongo client. How do I do this?

Dave Sag
  • 13,266
  • 14
  • 86
  • 134

2 Answers2

4

What about:

RUN sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
RUN sudo apt-get install -y mongodb-org-shell
RUN sudo apt-get install -y mongodb-org-tools

as suggested here?

mgaido
  • 2,987
  • 3
  • 17
  • 39
2

@mgaido 's answer is mostly correct.

It works for Ubuntu based Linux system, I find this post while seeking solution for my Docker instance and this helped.

But my Docker's operating system is based on a Debian distribution, I went through THIS POST to find it out.

Then on MongoDB's official documentation site, you should be able to select matched Docker operating system and follow the installing steps. Then MongoDB will be installed correctly.

paradox
  • 258
  • 4
  • 19
  • 1
    Saved my day. From last 6 hours I was trying to find a solution to install mongo-shell in Node docker image as mongoose would need it. I tried all the solutions but all failed at some steps somewhere. Finally got this thing, and found out that I was trying all the Ubuntu solutions while the Node image was based on Debian. Thank you so much @paradox. It just saved my day. – Swr7der Nov 30 '20 at 21:28
  • Thanks so much for this post @paradox. Fixed it for me too. For reference, these are the steps I followed to get the mongo shell working on my Debian GNU/Linux 10 docker container https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/ – piedpiper Mar 27 '21 at 00:13