Install MongoDB Enterprise with Docker

Important

The recommended solutions for using containers with MongoDB are:

Note

This procedure uses Docker’s official mongo image, which is supported bythe Docker community and not MongoDB.

If the above recommended solutions do not satisfy your needs,follow the steps in this tutorial to manually installMongoDB Enterprise withDocker.

Considerations

A full description of Docker is beyond the scopeof this documentation. This page assumes prior knowledge of Docker.

This documentation only describes installing MongoDB Enterprise with Docker,and does not replace other resources on Docker. We encourage you to thoroughlyfamiliarize yourself with Docker and its related subject matter beforeinstalling MongoDB Enterprise with Docker.

Important

This procedure uses Docker’s official mongo image, which is supported bythe Docker community and not MongoDB. It supports only the majorversions listed in their repositiory, and only a specificminor version for each major version. The minor version can be foundin the Dockerfile in the folder for each major version.

Create a Docker Image with MongoDB Enterprise

Download the Docker build files for MongoDB Enterprise.

After you have installedDocker and set up aDocker Hub account, downloadthe build files from theDocker Hub mongo projectwith the following commands. Set MONGODB_VERSION to your majorversion of choice.

Docker Hub Mongo Project

The Docker Hub mongo project is not maintained by MongoDB. Any supportrequests should go to Docker.

  1. export MONGODB_VERSION=4.0
  2. curl -O --remote-name-all https://raw.githubusercontent.com/docker-library/mongo/master/$MONGODB_VERSION/{Dockerfile,docker-entrypoint.sh}

Build the Docker container.

Use the downloaded build files to create a Docker container image wrapped aroundMongoDB Enterprise. Set DOCKER_USERNAME to your Docker Hub username.

  1. export DOCKER_USERNAME=username
  2. chmod 755 ./docker-entrypoint.sh
  3. docker build --build-arg MONGO_PACKAGE=mongodb-enterprise --build-arg MONGO_REPO=repo.mongodb.com -t $DOCKER_USERNAME/mongo-enterprise:$MONGODB_VERSION .

Test your image.

The following commands run mongod locally in a Docker container and checkthe version.

  1. docker run --name mymongo -itd $DOCKER_USERNAME/mongo-enterprise:$MONGODB_VERSION
  2. docker exec -it mymongo /usr/bin/mongo --eval "db.version()"

This should output the shell and server version for MongoDB.

Push the Image to Docker Hub

Optionally, you can push your Docker image to a remote repository, like DockerHub, to use the image on other host machines. If you push the image to DockerHub, you can then run docker pull for each host machine onwhich you want to install MongoDB Enterprise via Docker. For complete guidanceon using docker pull, reference its documentationhere.

Check your local images.

The following command displays your local Docker images:

  1. docker images

You should see your MongoDB Enterprise image in the command output. If you do not, try Create a Docker Image with MongoDB Enterprise.

Push to Docker Hub.

Push your local MongoDB Enterprise image to your remote DockerHub account.

  1. docker login
  2. docker push $DOCKER_USERNAME/mongo-enterprise:$MONGODB_VERSION

If you log into the Docker Hub site, you should see the image listed under your repositories.