OpenFOAM® Installation on Mac using Docker
OpenCFD Ltd. uses Docker Hub to distribute pre-compiled versions of OpenFOAM for Linux, Mac OS X and Windows, including a complete development environment.
Docker containers enable binaries compiled on a given Linux environment to be run on other platforms without any performance degradation. Docker also operates on Windows and Mac OS X wrapped in a light-weight Virtual Box.
An image of OpenFOAM contains binaries and source code. The Docker environment provides:
- A complete development environment to compile local modifications and create executables.
- A consistent behaviour of the OpenFOAM across all platforms
Check if your system is supported by visiting https://docs.docker.com/engine/installation/
Please check for compatibility via https://docs.docker.com/docker-for-mac/ to determine whether your Mac supports docker or docker-toolbox, and follow the appropriate link below:
- Docker for Mac (Preferred): Download and install native docker from https://docs.docker.com/docker-for-mac/
- Docker-Toolbox (for older systems): Download the docker-toolbox from https://www.docker.com/products/docker-toolbox
After installing, open the Launchpad and locate the Docker Quickstart Terminal icon. Click the icon to launch a Docker Quickstart Terminal window.
Installing and running OpenFOAM
Docker for Mac
- Make sure you are in the Docker Quickstart Terminal window
- Make sure the Docker daemon is running
- Open the command line terminal and make the scripts executable
chmod +x installMacOpenFOAM chmod +x startMacOpenFOAM
Install OpenFOAM using:
Start working on the container using:
- This will open a new terminal with OpenFOAM environment fully installed. Note the script allows you to login as user called ofuser and mount your home directory.
cd /home/ofuser/workingDir cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity . cd cavity blockMesh icoFoam
- Click on the Docker.app to start Docker. The Docker whale in the top status bar indicates Docker is running.
- Download the following scripts and put them in a local directory, e.g. your home directory
Download the following scripts and put them in a local directory, e.g. your home directory
Download and create the Docker container for OpenFOAM by executing the first script (assuming it is in the home directory)
docker-machine ssh default $HOME/installMacOpenFOAM_dockerToolBox $HOME
This only needs to be done once per login. The first ever invocation will download the whole OpenFOAM installation so might take some time to finish. Any future invocations will take a few seconds only.
Make the start script executable
chmod +x startMacOpenFOAM_dockerToolBox
Start the Docker container with the second script:
This will open a new shell with the OpenFOAM environment fully installed and ready to use, e.g.
mkdir -p $FOAM_RUN run cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity . cd cavity blockMesh icoFoam
All user files inside the Docker environment are available on the host inside the home directory.
Note: It is not possible to launch ParaView from the container. Testing showed that launching a GUI from a container is slow; users are suggested to install the native ParaView version for your system, and use the built-in OpenFOAM reader and/or OpenFOAM data conversion tools
Frequently Asked Questions on Docker
- Is there any performance degradation when running via Docker?
No performance penalties are expected. On Linux, OpenFOAM inside Docker should run as fast as natively compiled code. On Windows and Mac OS X there may be a slight performance penalty associated with I/O.
- How do I check if the OpenFOAM image has been downloaded correctly?
Type the command
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE openfoamplus/of_v1706_centos73 latest 88d542266184 4 hours ago 1.574 GB
- the Docker daemon is started at boot time
- the user account is in the group ‘docker’
- Where are my files?
The user files inside Docker are visible (i.e. mounted) in your home area and can be operated on just like any other file.
- Why doesn’t paraFoam display?
- Make sure that your machine’s software is fully up-to-date. See if you can start a simple X-windows, non-graphics program, e.g.: xterm If this does not come up there may be a problem with the xhost access to the host screen. This is one of the steps inside the startOpenFOAM script.
- An alternative remedy is to install the native ParaView version for your system, and use the built-in OpenFOAM reader and/or OpenFOAM data conversion tools.
- How do I run parallel?
Same as any other OpenFOAM installation, e.g.: mpirun -np 2 icoFoam -parallel
- How do I run parallel on multiple computers?
This is not trivial inside the Docker environment. Also you might want to include optimised communication libraries (MPI) so it probably makes more sense to perform a native compilation.
- How do I compile code?
The Docker environment contains a full OpenFOAM development environment so all Allwmake, wmake, wclean etc. commands work (it is running the actual environment OpenFOAM was compiled in!)
- What does installOpenFOAM do?
It downloads the OpenFOAM image from the Docker Hub and creates a specialised container. This container
- mounts the home directory of the user with read/write access
- optionally channels the graphics
- sets up the OpenFOAM environment.
- I still have questions...
The Docker route to OpenFOAM is new and still being refined. It you have comments/tips please mail them to: docker (at) opencfd.co.uk.