How to setup Datafi Edge Server in Debian 11 with Docker for MSSQL DB
Published: 2022-07-08 19:58:14

> Datafi edge server is available as a container, so It can run anywhere a container can run. In this tutorial we are going to run the datafi edge server in a Debian 11 Server. 

### Prerequisites 

- A server/vm running Debian 11
- Basic understanding of Docker 
- Basic understanding of SSH commands


I've setup a Debian 11 Server in Azure, you can do the same anywhere including a onpremise machine. 

### 1. SSH into the server. 
![Debian 11 is running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pcwwwbr0ocijzlhxoqas.png)
 
### 2. Install docker 
Detailed instruction to install docker in Debian is available [here](https://docs.docker.com/engine/install/debian/), we are using the convenience script provided in the docker documentation 
```
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
``` 
To make sure the docker is installed and running, run this command. 
```
sudo docker run hello-world
```
it should print out `Hello from Docker!`. 
![Hello from Docker](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/77uvgk39d69xkf6rigta.png)
 
### 3. Download Datafi-CLI tool
`datafi-cli` is a simple CLI tool to configure edge-server. It can be run either in your local machine or in the server. In this tutorial, we are running it in the same debian server. 
```
# download the cli
curl -fsSL https://github.com/datafilabs/datafi-cli/releases/download/v1.0.0/dfcli-linux -o dfcli
# allow executing the cli 
sudo chmod +x ./dfcli
# make sure the version is printed 
./dfcli --version
```
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bbew93rhhlflggpspjh.png)

### 4. Run edge-server container. 
```
sudo docker pull datafi/es:latest
sudo docker run --rm -p 50051:50051 -p 443:443 datafi/es:latest 
```
when you run the container for the first time with the above command you will get a warning that says `E0706 05:22:13.617044       7 policy.go:112] error opening socket connection: token missing in policy`. You can ignore this now, as we don't have the container configured yet.

### 5. Configure the edge-server with the datafi-cli
In a new terminal, run datafi-cli `dataset add` command with required parameters including the service level credentials to the MSSQL db. 
```
# check if the credentials are valid, and the db is reachable. 
./dfcli dataset --type mssql --dbname WideWorldImporters --password "pass" --port 1433 --server datafi-mssql.database.windows.net --username user check
```
This will try to connect to the mssql database and make sure the given credentials are valid. If its able to connect, you will see `Connection successful`


```
# generate KEY to be used in the environment variable for the edge server container. 
./dfcli dataset --type mssql --dbname WideWorldImporters --password "pass" --port 1433 --server datafi-mssql.database.windows.net --username user --name "MSSQL" --endpoint "datafi.acme.com" --pointOfContact yourname@domain.com add
```
this will generate the KEY and save it in `key.txt`. You will also get a URL which you can use to add the edge-server to your Datafi workspace. 

### 6. Add edge-server to your Datafi workspace. 
If you don't have a Datafi account, go to https://home.datafi.us/register and create a new workspace

The use the link you got in the previous step to add the newly added edge server to the workspace. Follow the instructions on the screen and save the dataset. 

### 7. Restart the Edge Server container with `KEY` environment variable 

### 8. Go to https://home.datafi.us/dataview to access the newly added dataset.