CFD Online Logo CFD Online URL
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Installation

[] A Mac OS X of23x Development Environment Using Docker

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 3 Post By rt08

LinkBack Thread Tools Search this Thread Display Modes
Old   January 8, 2016, 14:53
Default A Mac OS X of23x Development Environment Using Docker
New Member
Ryan Tunstall
Join Date: Sep 2013
Posts: 10
Rep Power: 12
rt08 is on a distinguished road
Apologies for the long post.

In summary the idea is to basically have a Docker container which essentially has OpenSUSE (as on my workstation) with all the OpenFOAM dependencies and the basic OpenFOAM install. This can be run on a Mac (from the OS X terminal), with the user’s OpenFOAM files readily shared from a folder in OS X (so we can still browse and edit them using our favourite OS X tools). This is easier to install than native OS X OpenFOAM, and provides an environment that is very similar to that on workstations and clusters. It is a lighter-weight solution and allows for much better OS X integration when compared to running OpenFOAM from a full Linux virtual machine in OS X. I suspect that like many here, my MacBook is really just used for development work (writing code and testing it builds), whilst any cases are run on my workstation or cluster. What I outline below is well suited to this usage profile.

See this recent article for a summary of Docker and it's advantages for OpenFOAM - though this seems to be more focused on using a completely standard OpenFOAM build without additional libraries/apps etc by downloading one of several existing Docker containers. I've been thinking about how we can use Docker to make it easier to install OpenFOAM on a Mac, that will:
  • Allow for an efficient developer environment to make custom libraries, solvers and tools, e.g. files easily accessible in OS X (see in Finder, use OS X apps to edit etc.) with minimal fuss to then actually compile them (e.g. don’t need to start manually rsyncing etc.).
  • Make installs simpler and faster, and prevent things breaking whenever there is an update to OS X
  • Portable - doesn’t require a continuous or regular network connection (otherwise we might as well just write source code on OS X, upload it and compile over ssh)
  • Provide an environment that is consistent with that on workstations and clusters (compilers and third party dependencies). For example, I have previously had issues where things compile in gcc on a cluster but not in clang on OS X and vice versa.
  • Minimal performance disadvantage - this is the tricky bit

Docker behaves a little differently on OSX than how it does on Linux distros. Docker containers are actually run inside a custom 'docker-machine' virtual machine (using virtualbox) rather than in pure OSX, this virtual machine is however very very light weight. The OSX /Users/[USER NAME] directories are automatically shared to the virtual machine as default and can then be very easily mounted into a Docker container. However due to limitations in virtual box’s file sharing (vboxsf) used by Docker this results in quite a degradation in read/write performance (see Hopefully Docker will eventually resolve this by switching from vboxsf to NFS or similar.

Due to the virtual machine setup, sharing files which are stored in Docker containers (or Docker volumes) back into OS X is challenging as they are buried somewhere in the docker-machine's virtual disk image. The only way I have found is to ssh into docker-machine and browse/edit files in the terminal (after using a Docker command to look up where they are actually stored) but then we don’t have any real OS X integration (can’t view files in the Finder or access them in apps). I have tried using sshfs and various virtual disk image mounting tools without success. There are various third party add ons that make attempts to address various aspects of this but none are a complete solution and many introduce other problems.

There is thus a balance between having good OpenFOAM performance and having good OS X integration. I have considered and tested three options:
  • Have the OpenFOAM source code stored and compiled in a Docker container, and also store the OpenFOAM data in the virtual machine. This provides the best performance, but because of the explanation in the previous paragraph we don’t have very good OS X integration - we have to ssh into the docker-machine to view or edit files and can’t access them in native OS X apps.
  • Have everything stored in OS X (noting that the OpenFOAM source code must be on a sparseimage!), then mount this as a shared folder into a Docker container which has all the required dependencies installed. We can then load this container and compile OpenFOAM. This provides the best OS X integration but due to limitations in virtual box file sharing (vboxsf) read/write performance takes a big hit. Just compiling OpenFOAM takes significantly longer. It also makes your Docker container a lot less portable, if you intend to use Docker on several machines to ensure a consistent environment.
  • Have the OpenFOAM source code stored and compiled in the Docker container and have the user’s files mounted into the Docker container as a volume shared from OS X (So they can be readily accessed natively in OS X). This provides a good balance and is much quicker in terms of compilation time of user libraries and running cases when compared to sharing all OpenFOAM files from OS X.
Since I don’t need to modify any of the original source code for OpenFOAM myself (I write extensions in the user directory), I am happy to use the last option; I am however able to modify and compile anything in my user/applications folder, where I do my coding. I believe this meets the above requirements reasonably well.

Note that if we were to run the same Docker container in a Linux distro this approach would be ideal. There'd be no slow down by mounting the user files in this way (since they don't need to pass through the intermediate docker-machine's vboxsf system) and we'd easily be able to browse the OpenFOAM source code stored in the container on the linux OS (because unlike on a Mac it's not buried in docker-machine's virtual disk image). So this approach is also suitable if you want to use this same OpenFOAM container on your mac and workstations/clusters (to ensure a fully consistent environment).

Here is my setup for OpenFOAM 2.3.x, though it could easily be modified to run any other version of OpenFOAM:

  • Docker toolbox, downloaded from here:
  • Any commands below should be run from a `Docker QuickStart Terminal’, though I will describe later how you can run them from any terminal. When you launch this for the first time in a given session, the virtual machine will be started, taking a few seconds - it won’t need to do this again though until you log out.

Basic OpenSUSE
  • Get the basic OpenSUSE container:
    docker pull opensuse
  • To run an OpenSUSE terminal with the OSX users home directory mounted in the /home folder:
    docker run -t -i -v $HOME:/home/ opensuse /bin/bash

of23xfull Docker container
  • OpenFOAM source and ThirdParty directories are stored and compiled in the Docker container (as are all dependencies). The user directory is stored in OS X and mounted as a shared volume to the Docker container.
    • Extract the attached zip file to: ~/Docker/:
    • Build the container from the included Dockerfile using:
      cd ~/Docker/of23x/of23xfull; docker build -t of23xfull . >& build.log
    • Run using:
      docker run -t -i -v $HOME/Docker/of23x/foamUser-2.3.x:/home/foamUser/OpenFOAM/foamUser-2.3.x of23xfull
    • I have an alias in .bash_profile for this, which will work when run from a docker terminal:
      alias of23xusd='docker run -t -i -v $HOME/Docker/of23x/foamUser-2.3.x:/home/foamUser/OpenFOAM/foamUser-2.3.x of23xfull'
  • If you do not care about OS X integration, then I would suggest that you make a Docker volume container (see and store the user data in there and mount that in the docker run command instead of your OS X home directory. This will improve read/write performance but you will have difficulty in accessing these files in the Finder or OS X apps, though if anyone has any ideas please let me know (see above for what I’ve tried)!

How to actually then do OpenFOAM stuff:
  • Start a Docker Quick Start Terminal
  • Launch the Docker container (assuming you have set up the aliases in .bash_profile):
  • Source OpenFOAM:
  • Do whatever you want in OpenFOAM!

Running multiple of23x containers at once:
  • You can run multiple containers at once in different terminal windows or tabs, you can do this graphically simply by clicking on the Docker Quick Start Terminal Icon and then launching the alias for the relevant container
  • You can also easily turn an existing terminal window or tab into a Docker terminal by running:
    • Code:
      /Applications/Docker/Docker\ Quickstart\
    • You can then start another instance of your Docker container, I have made an alias for this called docker_tab in .bash_profile
  • Alternatively once Docker machine (the virtual machine running in virtual box that can run Docker containers) is running we can ssh into this machine and run more instances of containers using:
    • Code:
      docker-machine ssh default
    • or
      ssh docker@[IP Listed when VM started]
    • with password tcuser

Attached Files
File Type: zip (6.7 KB, 19 views)
wyldckat, cutter and davibarreira like this.
rt08 is offline   Reply With Quote

Old   February 28, 2016, 19:00
Francisco T
Join Date: Nov 2011
Location: Melbourne, Australia
Posts: 64
Blog Entries: 1
Rep Power: 14
frantov is on a distinguished road
looks really interesting. I can run now blockMesh...

how can edit files? for example using an osx text editor like "open"

I got:
open transportProperties
bash: open: command not found

thanks in advance!
frantov is offline   Reply With Quote


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[] Docker vs Not Docker v2 AND installing editors into Docker u2berggeist OpenFOAM Installation 1 July 10, 2018 02:58
OpenFOAM v3.0+ ?? SBusch OpenFOAM 22 December 26, 2016 14:24
[] Docker OpenFOAM install error on Mac OS X dersh OpenFOAM Installation 10 May 6, 2016 12:49
CFX11 + Fortran compiler ? Mohan CFX 20 March 30, 2011 18:56
Software development environment jojo Main CFD Forum 12 July 14, 2006 08:14

All times are GMT -4. The time now is 14:31.