Deploy PostgreSQL service with D2C.io

This guide helps you to deploy a PostgreSQL (StandAlone and MasterSlave) 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 better understanding 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 creates 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 PostgreSQL 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 PostgreSQL bar.

Creating a PostgreSQL service. Service settings

Name

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. cooper-1) or alias-names (e.g. cooper-master or cooper-slave).

Configuration

At this step, you can choose a configuration for a service. For PostgreSQL, we support StandAlone and MasterSlave configurations. MasterSlave configuration requires to have at least two hosts (two containers will be deployed – one master and one slave).

Version

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

Superuser login

In this field, you can specify login for a superuser.

Superuser password

Password for a superuser

Database name

Create a name of a database after deploying.

In most of the cases, that is enough for deploying a database. You can now select hosts and create a service. Data services also have advanced settings. We show them below.

Creating a PostgreSQL service. Select hosts

At this image shown selected hosts block for MasterSlave 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 MasterSlave 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 a PostgreSQL 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 PostgreSQL. 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
You can specify environment variables for your application. They can be edited after creating a service.

What next?

In the next article we talk about:

  • maintaining data services: creating backups, scaling, checking containers logs and metrics, updating version