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.
- Install Docker daemon if you already have not
- 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
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
CONTAINER ID IMAGE
Next, find the IP Address of the running container
$ sudo docker inspect f2794236e8e6 |grep “IPAddress”
Finally connect to the container from host
$ mongo 172.17.0.2
MongoDB shell version: 3.2.11
connecting to: 172.17.0.2/test
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.
This image creation was automated with the following Dockerfile
LABEL “vendor”=”BroadTech Innovations PVT LTD”
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
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