-
Notifications
You must be signed in to change notification settings - Fork 83
Code_Saturne in a Docker container
- Docker should be installed on the machine, both to create the Code_Saturne image and to run the container.
- A fast internet connection is preferable.
Create a file named Dockerfile
with the following content:
FROM ubuntu:18.04 as builder
RUN apt-get update -y \
&& apt-get upgrade -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata \
&& apt-get install -y \
wget zlib1g-dev \
vim \
gfortran g++ gcc make cmake \
python3 python3-pyqt5 \
pyqt5-dev pyqt5-dev-tools \
openmpi-bin libopenmpi2 libopenmpi-dev \
&& apt-get autoremove \
&& apt-get clean
#---------------------------------------------------------
# hdf5 1.12.3
#---------------------------------------------------------
ARG hdfdir=/opt/hdf5-1.12.23
RUN wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.3/src/hdf5-1.12.3.tar.bz2 --directory-prefix=/tmp/ \
&& tar -jxvf /tmp/hdf5-1.12.3.tar.bz2 -C /tmp/ \
&& rm -r /tmp/hdf5-1.12.3.tar.bz2 \
&& mkdir ${hdfdir} \
&& cd /tmp/hdf5-1.12.3 \
&& ./configure CC=mpicc FC=mpif90 CXX=mpic++ \
--prefix=${hdfdir} --enable-build-mode=production --enable-parallel \
&& make -j \
&& make install \
&& rm -rf /tmp/hdf5-1.12.3 \
&& chmod -R 777 ${hdfdir}
#---------------------------------------------------------
# MED 5.0.0
#---------------------------------------------------------
ARG meddir=/opt/med-5.0.0
RUN wget https://files.salome-platform.org/Salome/medfile/med-5.0.0.tar.bz2 --directory-prefix=/tmp/ \
&& tar -jxvf /tmp/med-5.0.0.tar.bz2 -C /tmp/ \
&& rm -r /tmp/med-5.0.0.tar.bz2 \
&& mkdir ${meddir} \
&& cd /tmp/med-5.0.0 \
&& ./configure CC=mpicc CXX=mpic++ --prefix=${meddir} \
--with-med_int=long --disable-python --disable-fortran --with-hdf5=${hdfdir} \
&& make -j \
&& make install \
&& rm -rf /tmp/med-5.0.0 \
&& chmod -R 777 ${meddir}
#---------------------------------------------------------
# Code Saturne, get sources
#---------------------------------------------------------
ARG version=8.0.2
RUN wget http://www.code-saturne.org/cms/sites/default/files/releases/code_saturne-${version}.tar.gz --directory-prefix=/opt/ \
&& tar -zxvf /opt/code_saturne-${version}.tar.gz -C /opt/ \
&& rm -r /opt/code_saturne-${version}.tar.gz \
&& mv /opt/code_saturne-${version} /opt/code_saturne-${version}_src \
&& mkdir /opt/saturne_tmp /opt/code_saturne-${version}_build /opt/code_saturne-${version}_debug \
&& chmod -R 777 /opt/code_saturne-${version}_src
#---------------------------------------------------------
# Code Saturne, build
#---------------------------------------------------------
WORKDIR /opt/saturne_tmp
RUN ../code_saturne-${version}_src/configure PYTHON=/usr/bin/python3 CC=mpicc FC=mpif90 CXX=mpic++ \
--prefix=/opt/code_saturne-${version}_build --with-hdf5=${hdfdir} \
--with-med=${meddir} \
&& make -j \
&& make install \
&& rm -r /opt/saturne_tmp/* \
&& chmod -R 777 /opt/code_saturne-${version}_build
#---------------------------------------------------------
# Code Saturne, debug build
#---------------------------------------------------------
WORKDIR /opt/saturne_tmp
RUN ../code_saturne-${version}_src/configure PYTHON=/usr/bin/python3 CC=mpicc FC=mpif90 CXX=mpic++ CFLAGS='-g' FCFLAGS='-g' \
--enable-debug --prefix=/opt/code_saturne-${version}_debug --with-hdf5=${hdfdir} \
--with-med=${meddir} \
&& make -j \
&& make install \
&& rm -r /opt/saturne_tmp/* \
&& chmod -R 777 /opt/code_saturne-${version}_debug
#---------------------------------------------------------
#
# This is probably unsafe
#
# Use at your own risks
#
#---------------------------------------------------------
RUN echo 'root:rootpwd' | chpasswd \
&& apt-get install -y sudo gnome-terminal gedit \
&& apt-get autoremove \
&& apt-get clean \
&& useradd csuser \
&& mkdir /home/csuser \
&& chown csuser /home/csuser \
&& chgrp csuser /home/csuser \
&& echo 'csuser:userpwd' | chpasswd \
&& adduser csuser sudo
USER csuser
ENV HOME /home/csuser
WORKDIR /home/csuser
RUN echo "alias code_saturne=/opt/code_saturne-${version}_build/bin/code_saturne" >> /home/csuser/.bashrc \
&& echo "alias code_saturne_debug=/opt/code_saturne-${version}_debug/bin/code_saturne" >> /home/csuser/.bashrc
#---------------------------------------------------------
#
# This is probably unsafe.
#
# Use at your own risks.
#
# Build the image with:
# docker build -t cs_v6 .
#
# Clean all the docker images with:
# docker system prune --volumes
#
# [Linux] - Run the container with:
# docker run -it --rm -e DISPLAY=:0 -v ${HOME}/.Xautority:/root/.Xauthority:rw --net=host --name gnome-terminal cs_v6
#
# [Linux] - To share the local folder /aaa/bbb/ccc with the container, run the container with:
# WARNING: the container will be able to modify the corresponding folder
# docker run -it --rm -e DISPLAY=:0 -v ${HOME}/.Xautority:/root/.Xauthority:rw -v /aaa/bbb/ccc:/home/csuser/ccc --net=host --name gnome-terminal cs_v6
#
# [Linux] - When the container is running, activate the GUI:
# xhost +local:root
#
# [Linux] - When the container is stopped, undo:
# xhost -local:root
#
#---------------------------------------------------------
Open a terminal in the folder containing the Dockerfile. The following command will create a Docker image based on the aforementioned Dockerfile. The name of the Docker image will be cs_v6
docker build -t cs_v6 .
At this stage, a relatively large number of temporary Docker images are stored on the computer. They can be removed with the following command:
docker system prune --volumes
The following basic command can be used to start a container based on the image cs_v6, and open a terminal inside it:
docker run -it --rm --name gnome-terminal cs_v6
To activate the GUI, the following can be used:
docker run -it --rm -e DISPLAY=:0 -v ${HOME}/.Xautority:/root/.Xauthority:rw --net=host --name gnome-terminal cs_v6
Please note that the GUI will not work at first. The command xhost +local:root
must be entered in the host to activate it. When the container is no longer used, the command xhost -local:root
must be entered in the host.
It is possible to give additional options when running the Docker container. For instance, the option -v
allows file sharing between the host and the container.
This link could help: https://cuneyt.aliustaoglu.biz/en/running-gui-applications-in-docker-on-windows-linux-mac-hosts/
Install xQuartz:
brew install xquartz
Log out and in. Start xQuartz. In the security tab, allow connections from network clients. Use ifconfig to estimate your ip adress. Here, we will assume 192.168.1.1.
xhost + 192.168.1.1
Start your container:
docker run -it --rm -e DISPLAY=192.168.1.1:0 -v ${HOME}/.Xautority:/root/.Xauthority:rw --net=host --name gnome-terminal cs_v6
Type code_saturne gui
, you should see the graphical interface of Code_Saturne. When you are done with the container, simply type exit
in the terminal. Restore the original configuration:
xhost - 192.168.1.1
The Dockerfile file below can be used to create a container based on the development version of Code_Saturne.
FROM ubuntu:18.04 as builder
RUN apt-get update -y \
&& apt-get upgrade -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata \
&& apt-get install -y \
wget zlib1g-dev \
vim \
gfortran g++ gcc make cmake \
python3 python3-pyqt5 \
pyqt5-dev pyqt5-dev-tools \
openmpi-bin libopenmpi2 libopenmpi-dev \
&& apt-get autoremove \
&& apt-get clean
#---------------------------------------------------------
# hdf5 1.12.3
#---------------------------------------------------------
ARG hdfdir=/opt/hdf5-1.8.21
RUN wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.3/src/hdf5-1.12.3.tar.bz2 --directory-prefix=/tmp/ \
&& tar -jxvf /tmp/hdf5-1.12.3.tar.bz2 -C /tmp/ \
&& rm -r /tmp/hdf5-1.12.3.tar.bz2 \
&& mkdir ${hdfdir} \
&& cd /tmp/hdf5-1.12.3 \
&& ./configure CC=mpicc FC=mpif90 CXX=mpic++ \
--prefix=${hdfdir} --enable-production --enable-parallel \
&& make -j \
&& make install \
&& rm -rf /tmp/hdf5-1.12.3 \
&& chmod -R 777 ${hdfdir}
#---------------------------------------------------------
# MED 5.0.0
#---------------------------------------------------------
ARG meddir=/opt/med-5.0.0
RUN wget https://files.salome-platform.org/Salome/medfile/med-5.0.0.tar.bz2 --directory-prefix=/tmp/ \
&& tar -zxvf /tmp/med-5.0.0.tar.bz2 -C /tmp/ \
&& rm -r /tmp/med-5.0.0.tar.bz2 \
&& mkdir ${meddir} \
&& cd /tmp/med-5.0.0 \
&& ./configure CC=mpicc CXX=mpic++ --prefix=${meddir} \
--with-med_int=long --disable-python --disable-fortran --with-hdf5=${hdfdir} \
&& make -j \
&& make install \
&& rm -rf /tmp/med-5.0.0 \
&& chmod -R 777 ${meddir}
#---------------------------------------------------------
# Code Saturne, get sources
#---------------------------------------------------------
ARG version=master
WORKDIR /opt
RUN apt-get install -y build-essential autoconf automake libtool bison flex gettext python git \
&& apt-get autoremove \
&& apt-get clean \
&& git clone -b ${version} --single-branch --depth 100 https://github.com/code-saturne/code_saturne.git code_saturne-${version}_src \
&& cd code_saturne-${version}_src \
&& ./sbin/bootstrap \
&& mkdir /opt/saturne_tmp /opt/code_saturne-${version}_build /opt/code_saturne-${version}_debug \
&& chmod -R 777 /opt/code_saturne-${version}_src
#---------------------------------------------------------
# Code Saturne, build
#---------------------------------------------------------
WORKDIR /opt/saturne_tmp
RUN ../code_saturne-${version}_src/configure PYTHON=/usr/bin/python3 CC=mpicc FC=mpif90 CXX=mpic++ \
--prefix=/opt/code_saturne-${version}_build --with-hdf5=${hdfdir} \
--with-med=${meddir} \
&& make -j \
&& make install \
&& rm -r /opt/saturne_tmp/* \
&& chmod -R 777 /opt/code_saturne-${version}_build
#---------------------------------------------------------
# Code Saturne, debug build
#---------------------------------------------------------
WORKDIR /opt/saturne_tmp
RUN ../code_saturne-${version}_src/configure PYTHON=/usr/bin/python3 CC=mpicc FC=mpif90 CXX=mpic++ CFLAGS='-g' FCFLAGS='-g' \
--enable-debug --prefix=/opt/code_saturne-${version}_debug --with-hdf5=${hdfdir} \
--with-med=${meddir} \
&& make -j \
&& make install \
&& rm -r /opt/saturne_tmp/* \
&& chmod -R 777 /opt/code_saturne-${version}_debug
#---------------------------------------------------------
#
# This is probably unsafe
#
# Use at your own risks
#
#---------------------------------------------------------
RUN echo 'root:rootpwd' | chpasswd \
&& apt-get install -y sudo gnome-terminal gedit gitk \
&& apt-get autoremove \
&& apt-get clean \
&& useradd csuser \
&& mkdir /home/csuser \
&& chown csuser /home/csuser \
&& chgrp csuser /home/csuser \
&& echo 'csuser:userpwd' | chpasswd \
&& adduser csuser sudo
USER csuser
ENV HOME /home/csuser
WORKDIR /home/csuser
RUN echo "alias code_saturne=/opt/code_saturne-${version}_build/bin/code_saturne" >> /home/csuser/.bashrc \
&& echo "alias code_saturne_debug=/opt/code_saturne-${version}_debug/bin/code_saturne" >> /home/csuser/.bashrc
#---------------------------------------------------------
#
# This is probably unsafe.
#
# Use at your own risks.
#
# Build the image with:
# docker build -t cs_v6 .
#
# Clean all the docker images with:
# docker system prune --volumes
#
# [Linux] - Run the container with:
# docker run -it --rm -e DISPLAY=:0 -v ${HOME}/.Xautority:/root/.Xauthority:rw --net=host --name gnome-terminal cs_v6
#
# [Linux] - To share the local folder /aaa/bbb/ccc with the container, run the container with:
# WARNING: the container will be able to modify the corresponding folder
# docker run -it --rm -e DISPLAY=:0 -v ${HOME}/.Xautority:/root/.Xauthority:rw -v /aaa/bbb/ccc:/home/csuser/ccc --net=host --name gnome-terminal cs_v6
#
# [Linux] - When the container is running, activate the GUI:
# xhost +local:root
#
# [Linux] - When the container is stopped, undo:
# xhost -local:root
#
#---------------------------------------------------------