Folding@home with Docker Compose

|

Recommended System Specs:

  • At least 8 core 64-bit processor
  • At least 8 GB RAM
  • Windows 10 or Windows 11

Test System Specs:

  • 16 core i5-12600k processor
  • 64 GB DDR5 RAM
  • Windows 11 & Windows 10 VMs

Background

Folding@home is a distributed computing project that relies on volunteered compute capacity to help scientist develop therapeutics for diseases by simulating protein dynamics using the power of a large distributed computing cluster donated by thousands of companies and individuals around the world. (Link)

I found out about this project around the beginning of the Covid-19 pandemic. At the time they were making a push to find druggable zones on the Covid-19 virus’ protein spikes. (Link)

In this post, I’ll be attempting to use the Windows Subsystem for Linux and Docker Compose to launch and manage single or multiple Folding@HOME containers. The goal for these docker containers is to use a specified amount of spare CPU & RAM capacity while the user is working on the computer. It does well to scale down when the user needs the resources for their work but will scale back up when the specified capacity is available to it. I find the altruistic efforts of the Folding@home project incredibly inspiring so why not do some good with the extra CPU clock cycles on our Windows PCs?! 😀

Technical Details

For this project we have a few things that need to be setup before we can get the Docker containers running. I’ve automated the installation process as much as I could but there are some aspects of the install that still require user intervention.

Please visit my GitHub repository for the project to download the installation scripts. The instructions will be included on the README file there as well. Below I list the steps the script takes to install the project. Please make sure to run the scripts from the downloads folder on your account. For automation purposes, this directory is used by the script to keep things simple.

Script Step Through:

Script 1: Docker_Installer_part1.ps1

TLDR: This script is used to enable the prerequisites to installing Ubuntu with WSL. It also configures a scheduled logon task to run the next script after the script initiated reboot is completed.

  1. Line 1 changes the user preference for the execution policy of the shell
  2. Lines 2 – 7 elevates PowerShell to Run as Administrator
  3. Line 11 enables the Virtual Machine Platform feature. This is a requirement to install WSL.
  4. Line 15 enables WSL (Windows Subsystem for Linux )
  5. Line 17 changes directory to the current users downloads directory where the installation scripts are stored in the downloaded “FAHInstallerScripts” directory.
  6. Lines 19 & 20 copy the next scripts that will be run and places them in the public downloads folder. This is done so that they can be run using a scheduled task after the first reboot is completed and you have logged back in.
  7. Line 21 Copies the WSL configuration file that we use to specify the CPU & RAM amount we want to make available to WSL. This file can be edited to dedicate more or less to the Docker container.
  8. Lines 23 – 25 are used to configure a scheduled task that will run on the next login. This will kick of script 2 (Docker_Installater_part2.ps1) after the reboot initiated in Line 27.
  9. Line 27 reboots to complete WSL feature enablement.

Script 2: Docker_Installer_part2.ps1

TLDR: This script starts when you login after the reboot. It installs Ubuntu 20.04, updates WSL to WSL2, installs Docker and then configures the next scheduled task that will run script FAH_Setup.ps1. That script will kick off the final configuration that will setup the Folding@home containers.

  1. Lines 2 – 7 elevates PowerShell to Run as Administrator
  2. Lines 10 – 12 installs Ubuntu 20.04 for WSL. When ubuntu window starts up and requests a username. You can enter one if you’d like but the installation can proceed without it. If no username is entered, ubuntu will run with elevated sudo privileges when run.
  3. Line 13 pauses the script for 30 seconds so that the Ubuntu-20.04 install has enough time to complete. You can increase this time if your install takes longer and run it again.
  4. Lines 16 – 19 updates WSL to WSL2
  5. Lines 21 – 24 are used to progress through the WSL installer automatically.
  6. Lines 26 – 34 are used to set the defaults to WSL2 and Ubuntu-20.04
  7. Line 35 is just a idling period before the Docker installation starts
  8. Lines 41 -44 runs downloads and runs a quiet installation for Docker. This means that you will not see any installation prompts for the installer. This is the longest step of the process as the script downloads the ~550 MB Docker installer. Depending on your internet speed, this can take over 15 minutes.
  9. Line 46 removes the scheduled task used to run this script so that it doesn’t run on every reboot.
  10. Lines 48 – 50 are used to configure a scheduled task that will run on the next login. This script will initialize the Folding@Home Docker Compose installation.
  11. The silent installation of Docker should only take about 2 minutes after the installer is downloaded so line 52 waits for 2 minutes before restarting the computer.

FAH_Setup.ps1

  1. The script starts WSL on the PowerShell command line.

FAH_Setup2.ps1

  1. We want this script to type in the commands into the shell opened by FAH_Setup.ps1
  2. Make sure you click on the shell where WSL is opened so this script can send the commands we need to setup the Folding@home Docker Containers. This is done with lines 11 – 13.
  3. The build process for the image should take about 2 minutes.
  4. After this we use line 19 to start 2 containers running Folding@Home
  5. At this point the containers should be running and requesting jobs from Folding@home’s servers.

Tracking Your Contributions

you can track your contributions with the FAHControl app that can be downloaded with the installer available on Folding@home’s website. (Link)

View in Full Screen for Clarity 🙂

Instructions:

  1. Go to (Link)
  2. Download the Windows installer
  3. Run the installer
  4. The last screen asks if you want to Run Folding@home, uncheck the box.
  5. Find FAHControl in your Windows Start menu and run it
  6. At the bottom left of the FAHControl window, click add
  7. Find the port number of the container in the Docker control panel under Ports for the container. Enter it and click Save
  8. Repeat for each container
  9. You can then click the Viewer button to see the Work Unit protein your container has been assigned!

Troubleshooting

If the automated installation does not complete as intended, I recommend manually running the code below in a “Run as administrator” PowerShell terminal. You can start back from the top but also continue where the script had failed.

# Run to allow installations from the PowerShell terminal
set-executionpolicy -scope CurrentUser -executionPolicy Bypass -Force

# STEP 1: Enable Virtual Machine Platform feature
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

# STEP 2: Enable WSL feature
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

# Step 3: Reboot to complete steps 1 & 2
shutdown.exe /r /t 10

# Reopen PowerShell as administrator

# Step 4: Change directory to Users downloads folder
cd $home\downloads\

# Step 5: Install Ubuntu 20.04
wsl --install -d Ubuntu-20.04

# Step 6: Download the WSL2 update
Invoke-WebRequest -Uri "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" -Outfile wsl_update_x64.msi

# Step 7: Install the WSL2 Update. Run line below and just a couple of clicks to finish
.\wsl_update_x64.msi

# Step 8: Download Docker Installer
Invoke-WebRequest -Uri "https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe" -Outfile DockerDesktopInstaller.exe

# Step 9: Run Docker Installer
.\"DockerDesktopInstaller.exe" install --quiet

# Step 10: Reboot again
shutdown.exe /r /t 10

# Reopen PowerShell as administrator

# Step 11: Run WSL in PowerShell
wsl

# Step 12: Change Directory to user downloads folder
cd $home\downloads\

# Step 13: Clone the Github Repo
git clone https://github.com/linuxserver/docker-foldingathome.git

# Step 14: Change directory to the downloaded repo folder
cd docker-foldingathome

# Step 15: Build the Docker Image
docker build --no-cache --pull -t lscr.io/linuxserver/foldingathome:latest .

# Step 16: Copy the docker-compose.yml from my Github repo for the project into the Docker-foldingathome directory
Link to file. https://github.com/briandevadason/FoldingAtHome-Docker-Compose/blob/main/docker-compose.yml

Step 17: Copy the .wslconfig from my Github repo for the project into your user folder. 
Paste into Windows explorer address bar: C:\Users\
Find your username and click to it. 
Copy the file here
Link to file: https://github.com/briandevadason/FoldingAtHome-Docker-Compose/blob/main/.wslconfig
This file can be edited to change the amount of resources you want to give the containers. The listed amounts are the minimum I recommend. The containers scale to your usage pretty well so it shouldnt affect your user experience.

# Step 17: Change directory to docker-foldingathome 
cd $home\downloads\docker-foldingathome

# Step 18: Create the amount of Folding@home containers that you would like to run. This example will start 2. 
docker compose up -d --scale foldingathome=2

Uninstallation Instructions

  1. Docker and the Folding@home applications can be removed from Control Panel as you would with any other application.
  1. Ubuntu can be uninstalled from the Start Menu
  1. WSL can be uninstalled from the Control Panel -> Programs & Features -> Turn Windows features on or off button.

Future Update Ideas

There are still a lot of improvements that can be made to this implementation. Below are the features and fixes I would like to implement in future updates.

  • Fully automated uninstallation script
  • Clean up tasks to remove files from public folders and disabling elevated execution policy
  • Instructions for updating the WSL configuration file. This is to increase or reduce the resources committed to WSL and the Docker containers.
  • Support for GPUs
  • Best configuration seems to be 2 docker containers with 4 processors allocated.

Leave a Reply

Your email address will not be published. Required fields are marked *