This guide helps you to deploy a MongoDB (StandAlone and ReplicaSet) service in a Docker container using the D2C platform. It might be helpful for beginners as well as for advanced developers.

Denis Zaripov
Product manager
Why Docker?
A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Containers isolate software from its surroundings, for example, differences between development and staging environments and help reduce conflicts between teams running different software on the same infrastructure.
Please, check out the original Docker post about containers for a better understanding of all the benefits of the technology.
Preparing
It’s easier to start if you have already connected a host.
You can start with our Demo host, but it is created only for one hour. If you need more time, please follow our guides for connecting cloud providers or connecting your own machine to D2C.
Creating MongoDB service
At first, you need to open or create any project and click “+Create service“. You will see a list of services which can be deployed with D2C:

Let’s go ahead and click on the MongoDB bar.
Creating MongoDB service. Service settings

Naming
The name should start with a letter and contain up to 16 characters (Latin letters, numbers, hyphen).
Each service has its unique name. Services can communicate with each other by container names (e.g. izzy-1
) or alias-names (e.g. izzy-master
or izzy-slave
).
Configuration
At this step, you can choose a configuration for a service. For MongoDB, we support StandAlone and ReplicaSet configurations. ReplicaSet configuration requires to have at least three hosts (three containers will be deployed – one master and two slaves).

Version
You can choose a version for your application from a list:

Root password
In this field, you can specify a root password for a database. In StandAlone configuration, it doesn’t required but obligatory for ReplicaSet. Root password can be changed after deployment.
In most of the cases, that is enough for deploying a database. You can now select hosts and create a service. Data services as MongoDB also have advanced settings. We show them below.
Creating MongoDB service. Select hosts

At this image shown selected hosts block for ReplicaSet configuration. At first click, you choose a host for the master container and then for slaves. Click once again if you need to change master and slave hosts.
There is an opportunity to change configuration from StandAlone to ReplicaSet after deployment, so you can choose what you need for a start and then scale when it needs.
Also, at this step you can create other hosts and choose them even they are not online yet (creating/setting up status). The containers will be deployed when they are ready.
After successful deployment your project should look like:

Creating MongoDB service. Advanced settings
Click “Show advanced settings”.

Ports
The first block in this area is Ports.

Access from the Internet is disabled by default. You can enable access from the Internet while creating or editing service. But it is not recommended for security reasons and it is not necessary for communication with services which are running in D2C. Containers are started inside a private network and have dynamically assigned local IP addresses. Apps can reference each other by container name. It does not matter on which host the service is running – all private network intercommunication is transparent for all services in your account.
Persistent data volumes
D2C separates the application itself from its data. Docker volumes are used to store persistent data. Data is stored locally on the hosts.

Configs
D2C creates a default config for MongoDB. You can change it using the “Edit” button.
Click on the “Generate new config” button if you need to return to default config.

Global dependencies
In this field, you can specify commands for installing global dependencies of your service.
Initial commands
Commands which are executed only once after deploying a service.
Environment variables

What next?
In the next article we talk about:
- maintaining data services: scaling, checking containers logs and metrics, updating version