OpenFOAM is famous for being difficult and even difficult to install. Most of the time, you need a working Linux environment to install and use OpenFOAM.
If you are a typical Windows user (like me!) or a MacOS user, and interested in using OpenFOAM, using Docker containers is probably the easiest way to get started. In this article, we will explain how to run OpenFOAM using Docker. The total time excluding the download time is 5~10 minutes!
First, you need to download Docker Desktop for your OS (Windows, Mac or Linux itself). You can download Docker Desktop from their website. It is OK if you are a student or you want to use Docker as an individual. But if you want to use Docker on your company workstation, you need to check whether you need to buy the Pro version or not.
After downloading, you can open the installer and follow the instructions. For the details, you can check this video (Disclosure: this does not belong to CFD Monkey).
Then you start the Docker Desktop application. When the Docker Desktop is running, you can now open your command line system (cmd or PowerShell if you are on Windows and terminal if on MacOS).
After that, you need to pull the OpenFOAM docker image for later use by the following command:
docker pull thawtar1990/of2012
It will download OpenFOAM-v2012 on Ubuntu 20.04 LTS. For more information, you can check on my Docker Hub repository.
Docker will download the necessary files and this will take a couple of minutes to half an hour depending on your internet connection.
Now we can use OpenFOAM! You need to run the Docker container using the following command:
docker run -v $Your_Target_Directory:/home/user/workDir -it thawtar1990/of2012 bash
You can replace $Your_Target_Directory with any folder name you want to store your OpenFOAM case files as the initial mounting point. For example, I used C:\ as below and now I am inside Ubuntu and I have access to my files in C: drive!
Next step is to test the OpenFOAM inside the Docker image. So, we can test with blockMesh. As we can see, now we are up and running!
May be it is too boring and tiresome to type the Docker run command everytime. May be it is better to create a shortcut for it. You can create your custom shortcut on Window 10 or 11 like this. First, right click on your Desktop and click New->Shortcut. Then inside the location of the item:
C:\Windows\System32\cmd.exe /c docker run -v $Your_Target_Location:/home/user/workDir -it thawtar1990/of2012 bash
Then, you can name it as โof2012โ and finish the creation. Now we don’t need to type the command again anymore! All we need to do is run the Docker Desktop and double click our shortcut.
If you want to change your working directory, you can change inside the Properties dialog box by right-clicking the shortcut.
That is! Installing and running OpenFOAM is easier than ever and can be done in 5 minutes!
If you want to try more OpenFOAM versions, you can check at my Docker Hub repository.
We have a bunch of custom OpenFOAM containers with special third party softwares like Dakota, OpenFAST and foamMooring already compiled so that you do not need to deal with the hurdles of having to deal with dependencies and having to compile these codes.
If you want to try more OpenFOAM versions and the compiled software packages, you can check at my Docker Hub repository.