# Initialize database using Docker

<p class="callout info">The purpose of this tutorial is to show how to initialize a database **MariaDB** required for Soffid IAM installation using Docker.</p>

## Prerequisites

1\. Install docker ( [https://docs.docker.com/install/](https://docs.docker.com/install/) )

2\. Create a docker network, that network allows you to connect containers to the same bridge network to communicate:

```shell
sudo docker network create -d bridge NETWORKNAME
```

<p class="callout warning">For the correct installation of Soffid it is recommended not to use the underline character \_ in the network name.</p>

## MySQL/MariaDB

First step will be initialize MariaDB with Docker, in this case we attach the container to an exist network:

```shell
sudo docker run -d --name mariadb-service  --network=NETWORKNAME -e "MYSQL_ROOT_PASSWORD=ADMIN_PASSWORD" mariadb
```

Second, you can check the deployed containers:

```shell
sudo docker ps
```

Then, you must connect to the created container:

```shell
sudo docker exec -i -t mariadb-service  /bin/bash
```

In order to configure MySQL database you need access to the database administration tool (mysql) with superuser permissions using a TCP/IP connection. If needed, please create a user for the Soffid installation. If you don't have such a user, or don't know its password, please access MySQL as root, execute the **mysql** tool and create the user with **grant command** *(where ADMIN\_USER is the user to be used during the installation process to create the soffid repository database and ADMIN\_PASSWORD is the required password).*

Coonect to MySQL:

```western
mysql -u root -p
```

Create database and grant permissions:

```shell
create database soffid;
use soffid;
grant all privileges on *.* to ADMIN_USER@'%' identified by 'ADMIN_PASSWORD' with grant option;
```

In addition, in order to be able to manage big files, like process definition or software addons, we have to modify **max\_allowed\_packet** parameter on MySQL. This parameter is commonly allocated on the /etc/mysql/my.cnf file.

<div data-hasbody="true" data-macro-name="code" id="bkmrk-%5Bmysqld%5D-max_allowed"><div><div><div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="code"><div><div>`[mysqld]`</div><div>`max_allowed_packet=128M`</div></div></td></tr></tbody></table>

</div></div></div></div><p class="callout success">If the version of MariaDB is 10.1.38, or newer, the recommended value for max\_allowed\_packet<span lang="en"> </span> is 512M</p>

Note: in the case we will obtain the next '*The size of BLOB/TEXT data inserted in one transaction is greater than 10% of redo log size. Increase the redo log size using innodb\_log\_file\_size*.' error trying to upload an addon, we may update the default value of this mysql/mariadb parameter. This parameter is commonly allocated on the /etc/mysql/my.cnf file.

<div data-hasbody="true" data-macro-name="code" id="bkmrk-%5Bmysqld%5D-innodb_log_"><div><div><div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="code"><div><div>`[mysqld]`</div><div>`innodb_log_file_size=256M`</div></div></td></tr></tbody></table>

</div></div></div></div>If you are installing on a Ubuntu 18.04 server, default character set is set to utf8mb4. Using this character set can cause problems, as many index sizes will exceed maximum key size of 767 bytes. To prevent this problem, change following settings:

<div data-hasbody="true" data-macro-name="code" id="bkmrk-%5Bmysqld%5D-character-s"><div><div><div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="code"><div><div>`[mysqld]`</div><div>`character-set-server  = Latin1`</div><div>`collation-server      = Latin1_general_ci`</div></div></td></tr></tbody></table>

</div></div></div></div>Alternatively, if UTF character set is required, write the following settings:

<div data-hasbody="true" data-macro-name="code" id="bkmrk-%5Bmysqld%5D-character-s-0"><div><div><div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="code"><div><div>`[mysqld]`</div><div>`character-set-server  = utf8mb4`</div><div>`collation-server      = utf8mb4_general_ci`</div><div>`innodb_large_prefix   = ``1`</div><div>`innodb_file_format    = Barracuda`</div><div>`innodb_file_per_table = ``1`</div></div></td></tr></tbody></table>

</div></div></div></div>Following [this link ](https://confluence.soffid.com/display/SOF/Soffid+3%3A+Creating+a+multi-master+MariaDB+cluster) you will find the steps to setup a two nodes database cluster.

### Video Tutorial

#### MariaDB initialization using Docker

<iframe allowfullscreen="allowfullscreen" height="314" src="https://www.youtube.com/embed/mDJeSRbrn7w" width="560"></iframe>