From CAC Documentation wiki
Revision as of 08:36, 25 September 2020 by Crm17 (talk | contribs)
Jump to navigation Jump to search

This page describes how to run OpenFOAM in a docker container in Red Cloud.

[QUESTION #1 FOR CAC REVIEW: Do we want to provide any guidance here about what flavor of instance to launch? Can any of this OpenFOAM code be run in parallel, and if so, do we want to provide any instruction on how to do so?]

[QUESTION #2 FOR CAC REVIEW: Is there a Dockerfile available that builds this container? Not something to show externally for users of this page, but I'm just curious to see it.]

Launch Instance

Launch a Red Cloud instance using the openfoam-docker-2020-09-17 image. See the Red Cloud Linux instances page on how to launch an instance, and the Images page for more information about images on Red Cloud. You can launch an image either directly from the openfoam-docker-2020-09-17 image page, or by following the general instructions for creating a Red Cloud Linux instance and choosing the openfoam-docker-2020-09-17 image as the source for the new instance.

Run and Attach to Docker Container

1. ssh to the Red Cloud instance

  • Because the openfoam-docker image is based upon an Ubuntu image, the username for your ssh command will be ubuntu, e.g., with a command such as:
ssh -i my_key.pem ubuntu@<IP address of your instance>
  • See the documentation on Secure Shell (SSH) for more information on connecting to your instance.

2. Run and attach a docker container containing OpenFOAM image: docker container run -ti openfoam/openfoam7-paraview56

  • After executing this command, you should notice that the command prompt has changed, as the docker container is now running and is providing you with access to a separate bash shell running within the container.


We present here two tutorials that are included in the $FOAM_TUTORIALS directory. Feel free to explore the contents of that directory if you'd like to examine other tutorials.


This example is based on the experimental work of Pitz and Daily (1981). It features a backward facing step. Such a "classic" case is instructive for comparing different turbulence models with respect to the size and shape of the recirculation zone.

  • Now that you are running a bash shell within the OpenFOAM docker container, first make a unique working directory and copy the pitzDaily example code into the directory, by executing the following commands within the docker bash shell:
WORK_DIR=$FOAM_RUN-$(whoami)-$(date +%s) 
echo $WORK_DIR
mkdir -p $WORK_DIR 
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily .
cd pitzDaily
  • Next, let's run the simulations. Execute these commands in sequence. They will run quickly (under a minute), and will produce some printed output.
    • blockMesh
    • simpleFoam
  • If you're curious about where those applications are within the container, you can make use of standard Linux commands to examine the PATH that has been set up within the container, and figure out where these applications are stored:
    • echo $PATH
    • which blockMesh

IcoFoam Cavity

This is a second example that we will want to run in a separate subdirectory. First execute the following commands, in order to go back to the working directory ($WORK_DIR) and copy the code for the second example:

cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity . 
cd cavity
  • Now run the simulations:
    • blockMesh
    • icoFoam

Cleaning Up

  • Once you are finished running within your docker container, you can issue the command exit to terminate the bash shell running within the container and return to the outer bash shell running in your Red Cloud instance.
  • If you are done using your instance for the time being, you can logout (exit) and then shelve your instance so that you do not continue to accrue charges to your Red Cloud subscription. See our documentation for more information about managing your subscription.