Installing mongo client in a Docker container

11.8k views Asked by At

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?

2

There are 2 answers

1
mgaido On BEST ANSWER

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?

2
paradox On

@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.