Contact Us

Monday 10 July 2017

Deploy MongoDB on Docker container running Debian Stretch ( Debian 9.x )

Here is our public repository, that allows to deploy MogoDB on docker with a single command. We created a Docker image that runs debian for that.

Docker Pull Command
docker pull broadtech/debian-stretch-mongodb 
latest: digest: sha256:1af066db3b4c030fd14904c7e11c2021920cdb348a80d097ec1751ee29860ff0

This repository image contains Debian Stretch Linux from which MongoDB service can be run automatically.


1. Install Docker daemon if you already have not

2. Deploy MongoDB from the image in this repository
    $ sudo docker run broadtech/debian-stretch-mongodb:latest

You will see something similar to this on screen:

Unable to find image 'broadtech/debian-stretch-mongodb:latest' locally
latest: Pulling from broadtech/debian-stretch-mongodb
c75480ad9aaf: Already exists
2573503b640f: Pull complete
85850e4fdb73: Pull complete
867e37a24fb6: Pull complete
821911695928: Pull complete
Digest: sha256:d48138959bf114b88c01a6ba1195708a6dcd6b84df79eca0b580b34e13cdfe30
Status: Downloaded newer image for broadtech/debian-stretch-mongodb:latest

Next MongoDB will start automatically and Listen on TCP PORT 27017
You can connect to it from host using any MongoDB client

First get container ID

$ sudo docker ps -a
f2794236e8e6 broadtech/debian-stretch-mongodb:latest

Next, find the IP Address of the running container

$ sudo docker inspect f2794236e8e6 |grep "IPAddress"
"SecondaryIPAddresses": null,
"IPAddress": "",
"IPAddress": "",

Finally connect to the container from host

$ mongo
MongoDB shell version: 3.2.11
connecting to:
Welcome to the MongoDB shell.

MongoDB sometimes comes without a default password and this has cause exposure of Data on the Internet.
So please be sure to provide passwords for users if you wish to expose your MongoDB server to the outside world.

More Information at

This image creation was automated with the following Dockerfile

FROM debian

LABEL "vendor"="BroadTech Innovations PVT LTD"
LABEL "vendor.url"=""
LABEL "maintainer"=""

RUN apt-get update && DEBIAN_FRONTEND=noninteractive
RUN DEBIAN_FRONT=noninteractive apt-get install -yq apt-utils
RUN DEBIAN_FRONTEND=noninteractive apt-get install -yq mongodb
RUN apt-get clean

EXPOSE 27017

CMD ["--dbpath", "/var/lib/mongodb"]
ENTRYPOINT ["/usr/bin/mongod"]

To run MongoDB in the background as a detached processed use the "-d" option with "docker run"

$ sudo docker run -d broadtech/debian-stretch-mongodb:latest

No comments: