This article explains how to install Mistika Workflows inside a docker container on a Linux desktop, with the main purpose to use the workflows GUI interactively


This particular example was made for running workflows in Ubuntu desktop, but it should be pretty similar in other desktop distros.


PREREQUISITES:


Install Ubuntu desktop: For this example let's suppose that you have installed Ubuntu desktop (other distros should also work), and you have created a user named "mistika"  which you will login (all commands below appearing without sudo are executed as the user mistika... )


Install a (modern) NVIDIA GPU in your system (Mistika Workflows on linux can not work without it).


CONFIGURATION INSTRUCTIONS:


1. Install NVIDIA driver:


sudo ubuntu-drivers install

sudo reboot


Check that the gpu is regognized:


nvidia-smi  


(it should show your gpu model)



2 - Make sure to login to an X11 (Xorg)  session, not Weyland. Weyland is not supported for Mistika Workflows. In some systems you can choose the session type in the login screen, while in other systems you may need to install Xorg manually. In any case this is out of the scope of this document.  


The X11 session must provide a nvidia OpenGL context.  To test it you can use glxinfo (if you do not have glxinfo installed just install mesa-utils or glx-utils, which will provide glxinfo). Then execute this:
```
glxinfo |grep vendor

server glx vendor string: NVIDIA Corporation
client glx vendor string: NVIDIA Corporation
OpenGL vendor string: NVIDIA Corporation
```

It needs to return NVIDIA as the OpenGL vendor as shown, not "Mesa" or any other opengl providers (or errors). Otherwise do not continue, because this method is not going to work. If you are sure that you are using Xorg and not weyland, then the next possible cause for those problems is the lack of a proper xorg.conf file. If it is that, it should be fixed with this:
```
sudo nvidia-xconfig
sudo reboot
```
Other causes are possible, but they are out of the scope of this document.



2. Install Docker (if not yet) and give docker access to your user


curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

sudo usermod -aG docker $USER

sudo reboot



3. Install nvidia-container-kit for docker


(Note: this is based on nvidia official instructions here , you may want to follow that link for getting newer versions ...)

 

sudo apt-get update && sudo apt-get install -y --no-install-recommends ca-certificates curl gnupg2


curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg  && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' |  sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list


sudo apt-get update

export NVIDIA_CONTAINER_TOOLKIT_VERSION=1.18.2-1


sudo apt-get install -y       nvidia-container-toolkit=${NVIDIA_CONTAINER_TOOLKIT_VERSION}  nvidia-container-toolkit-base=${NVIDIA_CONTAINER_TOOLKIT_VERSION} libnvidia-container-tools=${NVIDIA_CONTAINER_TOOLKIT_VERSION} libnvidia-container1=${NVIDIA_CONTAINER_TOOLKIT_VERSION}


sudo nvidia-ctk runtime configure --runtime=docker 

sudo systemctl restart docker 

sudo nvidia-ctk runtime configure --runtime=containerd 

sudo systemctl restart containerd



4. Install Mistika Workflows docker image


Create a text file named compose.yml, and copy/paste the compose.yml content provided in the mistikaworkflows docker repository:  https://hub.docker.com/r/sgomistika/mistikaworkflows


Note that the default compose.yml file only configures a few container internal volumes in order to make changes to the configuration files persistent.  In this file you may also need to change these settings:


- Add bind mounts for your media in the "workflows:" volume section of the compose.yml file, (an example is provided...) in order to give the container access to the storage paths where your media files are located, and also for the potential render destinations. A docker container can only access paths that are defined in there.


- If the license server is not the host server, an easy way to configure it is to change the SGO_ELMHOST variable in the compose.yml file, indicating the ip of the remote license server. 


Once you have the compose.yml configured, we will start it's containers and volumes:


docker compose up -d


The first time you execute this it will take a long while donwloading the docker image. But posterior executions should be very fast.


That will create two containers, sgoLicenseServer and MistikaWorkflows. The license server process (sgoLicenseServer.bin)  is executed automatically in the first container, but the workflows application is not started on its own just yet (we will do it in the next point):


If the local host is going to be its own license server, then go to point 3 of this article about the docker license server. Once you have activated your license then come back to this document and follow the points below.


5. Running workflows in the container


First thing you will need to restart the gdm service 

```
sudo systemctl restart gdm
```

Note: In principle this can be neccesary after every reboot (a workaroud to avoid this is explained later, but we will do it manually by now...).  Not all configuration and distros need this, but if you experience errors like "XCB error: 2" or if the mistika windows have visual glitches then restarting gdm should fix it. 


Now let's open the sgoActivationTool to setup the license:
```
docker exec MistikaWorkflows sgoActivationTool
```
The sgoActivationTool window should open. Then click "login" and login to your SGO account in the browser that will appear. Then close the browser and come back to the activation tool window to activate (or reallocate) your licenses as needed. 


Once the license is configured, let's execute the workflows application in the MistikaWorkflows container:
```
docker exec MistikaWorkflows workflows
```
The Mistika Workflows GUI should open.

For the next example, save a MyWorkflows.mwf file (create your own workflow example), and let's render it as a CLI example with parameters:
```
docker exec MistikaWorkflows workflows -r /opt/sgo/sgodata/Projects/MyWorkflows.mwf"
```
or if you want to see it in the GUI:
```
docker exec MistikaWorkflows workflows -A /opt/sgo/sgodata/MyWorkflows.mwf
```


6 - For further automation, we are going to create a "workflows" script emulating workflows native syntax (like if we didn't have docker). Create a "workflows" text file with this content:


File: workflows


Content:
```
#!/bin/bash
xhost +
docker exec MistikaWorkflows workflows "$@"

```
Install the new script:
```
chmod a+x workflows

sudo cp -f workflows /usr/bin/.
```

Now you can execute workflows like you would do on native installations without docker, even after reboots. For example:
```
workflows -r /opt/sgo/sgodata/Projects/MyWorkflows.mwf
```
Once you have tested that everything works you can also automate the gdm restart via a system service: 


File: /etc/systemd/system/restart_gdm_for_mistika.service


Content:
```
[Unit]
Description=Restart gdm for Mistika containers
After=graphical.target
After=network.target

[Service]
Type=simple
ExecStart=systemctl restart gdm
User=root


[Install]

WantedBy=graphical.target


```
Save it, and then execute:
```

sudo systemctl daemon-reload

sudo systemctl enable restart_gdm_for_mistika 

sudo reboot
```

After the reboot you should be able to execute workflows with no further actions, also including parameter support. Example:


workflows -A /opt/sgo/sgodata/Projects/MyWorkflows.mwf 


That's it. If you need more help please open support ticket at https://support.sgo.es/