Skip to content

Instantly share code, notes, and snippets.

@abzrg
Last active July 24, 2022 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abzrg/33d9173c872fb34efa055326859b0c5b to your computer and use it in GitHub Desktop.
Save abzrg/33d9173c872fb34efa055326859b0c5b to your computer and use it in GitHub Desktop.
Install OpenFOAM-3 using Docker
# OpenFOAM-3 can be installed on ubuntu 14.04 LTS
FROM ubuntu:trusty
# Install dependency and some softwares
# NOTE that you should not install build-essential as it clashes with
# the version of the compiler that openfoam is build with
RUN : \
&& apt-get update \
&& apt-get install -y \
git wget make tmux \
software-properties-common \
tree
# Install OpenFOAM
# NOTE that I change the value of WM_PROJECT_USER_DIR to /home/openfoam directory
# this is to prevent openfoam from creating a OpenFOAM/openfoam-3 directory in home
Run : \
&& add-apt-repository http://dl.openfoam.org/ubuntu \
&& sh -c "wget -O - http://dl.openfoam.org/gpg.key | apt-key add -" \
&& apt-get update \
&& apt-get -y install openfoam30 \
&& sed -i 's#export WM_PROJECT_USER_DIR=$HOME/$WM_PROJECT/$USER-$WM_PROJECT_VERSION#export WM_PROJECT_USER_DIR=$HOME#' /opt/openfoam30/etc/bashrc \
&& echo '. /opt/openfoam30/etc/bashrc' >> /etc/bash.bashrc
# Add a user (with password of '1234')
RUN : \
&& useradd -m openfoam -s /bin/bash -u 1000 \
&& usermod -aG sudo openfoam \
&& echo 'openfoam:1234' | chpasswd
WORKDIR /home/openfoam
# Switch to openfoam user
CMD su openfoam

OpenFOAM-3

OpenFOAM (openfoam.org) does not provide a docker image for OpenFOAM-3.

Installation

mkdir ~/OpenFOAM/$USER-3
mkdir ~/OpenFOAM/OpenFOAM-3

pushd $_

Now download The Dockerfile above and put it in the OpenFOAM-3 directory with the name Dockerfile. Then build the OpenFOAM-3 image

# Build an OpenFOAM-3 docker image from this Dockerfile
docker build -t openfoam-3 .

Now run openfoam-3 containers per below

# Set alias for this long command
#   For subsequent shell sessions put this into your shell config
alias of3='cd $HOME/OpenFOAM/$USER-3 && docker run -v $PWD:/home/openfoam -it --rm openfoam-3'

# Now Load OpenFOAM-3 environment with
of3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment