Issue 009 – August 22, 2020

It's Docker-time

Hey there,

It’s Robin from CFD Engine, I hope you had a good week of CFD 🤞

This week I’m back with some thoughts on Docker, an important part of my CFD toolbox, but maybe not yours.

I’ve mentioned in past issues that I’m not ready to switch to either of the new OpenFOAM releases. I’m not sleeping on them though, I’m trialling them both & I’m doing it using Docker.

This email is the CliffsNotes version of a deep dive into OpenFOAM in Docker that I wrote a while ago. Check it out if you’re thinking of taking Docker for a proper spin.

Docker what?

Let’s dodge the finer points for now & just think of Docker as a virtual machine. We can use it to bundle OpenFOAM (& it’s dependencies) into an image file, which can be run on any machine that has the Docker engine installed.

Compared to traditional VMs (& generalising a bit) Docker images are lightweight, they start quickly, they don’t take up much of the system resources & they’re isolated from the host system (& each other).

It’s slightly more complicated than that, but it’s a useful place to start.

Side note: a running Docker image is known as a container.

How I use Docker

Rather than installing a native version of OpenFOAM on my machine I install it into a Docker image.

When a new OpenFOAM version comes out I grab an Ubuntu Docker image & follow the Foundation/OpenCFD instructions to install their pre-compiled binaries. I save this custom image file on my machine & use it whenever I need to run that particular version of OpenFOAM.

It’s by far the easiest way to run OpenFOAM on Mac, but its also a convenient way to maintain a consistent CFD environment across different machines & platforms.

There are a few other “nice to haves” that we get from using OpenFOAM in Docker too…

Isolated

With only one OpenFOAM version in any given container, there’s no need to worry about different versions, libraries or dependencies treading on each other’s toes. I find that it also makes it less likely (although not impossible) that I’ll run something in the wrong OF version.

Disposable

I treat the containers as disposable & immutable. I start a fresh one each time I need to run OpenFOAM, I don’t make changes to them & I throw them away when I’ve finished. This way, they don’t degrade or drift during their lifespan – it’s like using a nice fresh install every time.

Build-Your-Own

Both OpenCFD & The Foundation provide their own Docker images, but they’re designed to be used in a way that never jived with me – your mileage may vary – give ’em a try. But I like to build my own.

Client Support

Let’s say I’m supporting a client who runs OpenFOAM on CentOS machines. I can grab a CentOS base image, install OpenFOAM and have a local environment that is very close to theirs for troubleshooting & support purposes – surprisingly useful.

A couple of tips…

Running OpenFOAM in Docker is slightly different to running it natively & I’ve seen plenty of new users tie themselves in knots trying to get to grips with it. So, here are a couple of quick tips if you’re thinking of taking OpenFOAM for a spin in a Docker container:

Don’t copy files in & out of the container

By default, your container has it’s own filesystem & no access to your local files. People get into knots, copying things in & out of the container. Instead, mount part (not all) of your local filesystem in the container & let your simulation data live there. This way, you’re less likely to accidentally loose data when a container is removed (or forget where you put it when you log out). As a bonus, you be able to access your simulation files using your local apps, like your fave text editor & ParaView, for example.

Local ParaView Only

Speaking of ParaView, install it natively on your system & use that. It will be much more responsive (& easier to use) than one running inside a Docker container. GUI programs in Docker containers aren’t for the faint hearted.

Use Dockerfiles

I mentioned that I build my own Docker images using Ubuntu & the pre-compiled binaries. However, I don’t do it interactively. Instead, I use a Dockerfile to automate the steps & provide a record of what was installed. I’ve posted a couple of example Dockerfile’s to GitHub that you can use as the basis for your own.

Check the readme for an example of how to use them.

How about you?

Running OpenFOAM in Docker isn’t for everyone, but I’ve found it to be a valuable addition to my CFD toolbox, solving a couple of otherwise tricky problems.

Do you use Docker with OpenFOAM? Does it solve a problem for you? Or is it more hassle than it’s worth?

Drop me a note & let me know your experience with Docker, I’m always keen to hear back from you.

Until next week, CFD safely

Signed Robin K