This article provides comprehensive instructions on configuring and deploying a MongoDB container on MedStack Control. Below are the steps to follow:
Steps
- Create a Docker volume to store the MongoDB data. Later on, you will map the data directory to the volume, which will allow the database’s data to persist beyond the lifecycle of the container.
- In the cluster overview page, click “Manage Docker”
- In the “Volumes” tab, click “New volume”
- Label the volume accordingly, e.g., “mongodb_data”, and click “Create” to create the Docker volume.
- Create or use a dedicated node for the MongoDB database. This will prevent application services and database processes from impacting each other.
- In the cluster overview page, click “Create node”
- Select the node size. For production environments, we recommend a “Large: 4 core 8 GiB” machine. After selecting a machine, click “Create” to deploy the node and allow time for it to provision.
- On the newly created node, click the “Actions” dropdown button and click “Labels”
- Create a new label and set the name to “mongodb” and the value to “true” , then click “Update” to attach the label to the node. Later on, this label will be used as a Placement Constraint to ensure MongoDB containers run on this node.
- Create the MongoDB service in Docker.
- In the cluster overview page, click “Manage Docker”
- In the “Services” tab, click “New service” and select “Custom Service”
- Configure the service as follows:
Name: MongoDB
Image: mongo
Internal Port: 27017
Environment Variable:
MONGO_INITDB_ROOT_USERNAME=user
MONGO_INITDB_ROOT_PASSWORD=Passw0rd!
Volume:
TargetPath: /data/db
Volume: mongoDbData
Placement Constraint:
node.labels.mongodb == trueNote, the MONGO_INITDB_ROOT_PASSWORD environment variable is set for demonstration purposes only. In a production environment, we strongly recommend mounting sensitive parameters to the service as a Docker secret.
- Click “Create service” to deploy the service.
Once the service has been deployed, you can interact with it from the service’s details page.