Run OpenFOAM with Docker

Published by rupole1185 on

Installing and Running OpenFOAM with Docker

Here’s a breakdown of how to install and run OpenFOAM using Docker:

1. Prerequisites:

  • Docker: Make sure you have Docker installed on your system. Download it from the official website (https://www.docker.com/).
  • Docker Compose (Optional): Docker Compose is a tool for defining and running multi-container Docker applications. You can install it using pip install docker-compose.

2. Find a suitable OpenFOAM Docker image:

There are several OpenFOAM Docker images available on Docker Hub. Some popular options include:

3. Pull the image:

Once you’ve chosen an image, pull it from Docker Hub using the following command:

docker pull <image-name>:<image-tag>

For example, to pull the OpenFOAM Foundation image with the latest version:

docker pull openfoam/openfoam:latest

4. Run OpenFOAM in a container:

You can run OpenFOAM in a container using the docker run command.

Basic command:

docker run -it -v <your_local_directory>:/home/openfoam/OpenFOAM/<version>/run -w /home/openfoam/OpenFOAM/<version>/run <image-name>:<image-tag> bash
  • -it: Run the container in interactive mode and allocate a pseudo-TTY.
  • -v: Mount your local directory to the container’s /home/openfoam/OpenFOAM/<version>/run directory. This allows you to access your files and save results.
  • -w: Set the working directory within the container.
  • <image-name>:<image-tag>: The name and tag of the OpenFOAM Docker image you pulled.

Example:

docker run -it -v ~/OpenFOAM_Projects:/home/openfoam/OpenFOAM/v2012/run -w /home/openfoam/OpenFOAM/v2012/run openfoam/openfoam:v2012 bash

5. Access OpenFOAM within the container:

Once the container is running, you can access OpenFOAM commands and tools:

# Navigate to the OpenFOAM directory
cd /home/openfoam/OpenFOAM/<version>/run

# Run OpenFOAM commands
blockMesh
simpleFoam

6. Using Docker Compose (Optional):

If you want to define a more complex multi-container setup with OpenFOAM and other services, Docker Compose can be helpful. You can define your services in a docker-compose.yml file and use the docker-compose up command to start them.

Example docker-compose.yml:

version: "3.7"
services:
  openfoam:
    image: openfoam/openfoam:latest
    volumes:
      - ./projects:/home/openfoam/OpenFOAM/v2012/run
    working_dir: /home/openfoam/OpenFOAM/v2012/run
    command: bash

Running with Docker Compose:

docker-compose up -d

7. Accessing OpenFOAM in your local environment (Optional):

You can use port forwarding to access OpenFOAM from your local machine. Add the -p <local_port>:<container_port> flag to the docker run command:

docker run -it -p 8080:80 -v ~/OpenFOAM_Projects:/home/openfoam/OpenFOAM/v2012/run -w /home/openfoam/OpenFOAM/v2012/run openfoam/openfoam:v2012 bash

This will map port 8080 on your local machine to port 80 inside the container. You can then access OpenFOAM via http://localhost:8080.

Remember to choose the correct image and version of OpenFOAM based on your project requirements.

Additional Notes:

  • Make sure your local directory is accessible to the container.
  • You can customize the container’s environment variables for different needs.
  • Use Docker’s networking options to connect your OpenFOAM container to other services.
  • Consider using a Docker volume to persist your OpenFOAM data between container runs.

By utilizing Docker, you can easily set up and run OpenFOAM in a reproducible and isolated environment. This provides greater flexibility, portability, and scalability for your simulation projects.


CloudHPC is a HPC provider to run engineering simulations on the cloud. CloudHPC provides from 1 to 224 vCPUs for each process in several configuration of HPC infrastructure - both multi-thread and multi-core. Current software ranges includes several CAE, CFD, FEA, FEM software among which OpenFOAM, FDS, Blender and several others.

New users benefit of a FREE trial of 300 vCPU/Hours to be used on the platform in order to test the platform, all each features and verify if it is suitable for their needs


Categories: OpenFOAM

1 Comment

Run OpenFOAM docker on a SLURM cluster - Cloud HPC · 26 August 2024 at 2:38 pm

[…] a comprehensive guide on running OpenFOAM within Docker containers on a SLURM cluster, along with best practices and troubleshooting […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *