Code_Saturne in a docker container

All questions about installation
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
C.FLAG.
Posts: 32
Joined: Fri Apr 08, 2016 2:19 pm

Code_Saturne in a docker container

Post by C.FLAG. »

Hello,

Following a relatively large number of installation issues (unexperienced users, exotic platforms, ...), I expose below an experiment towards a more universal way to use Code_Saturne based on Docker. Below is a Dockerfile for Code_Saturne 6.0.2 with MED and HDF5 based on Ubuntu 18:

Code: Select all

FROM ubuntu:18.04 as builder

RUN apt-get update -y
RUN apt-get upgrade -y
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
RUN apt-get install -y                             		\
        wget zlib1g-dev                                         \
        vim gedit git gitk                                      \
        gfortran g++ gcc make                                   \
        python3 python3-pyqt5                                   \
        pyqt5-dev pyqt5-dev-tools                               \
        openmpi-bin libopenmpi2 libopenmpi-dev
RUN apt-get autoremove
RUN apt-get clean

#---------------------------------------------------------
# hdf5 1.10.6
#---------------------------------------------------------

RUN wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.6/src/hdf5-1.10.6.tar.gz --directory-prefix=/tmp/ \
        && tar -zxvf /tmp/hdf5-1.10.6.tar.gz -C /tmp/ \
        && rm -r /tmp/hdf5-1.10.6.tar.gz
RUN mkdir /opt/hdf5-1.10.6
WORKDIR /tmp/hdf5-1.10.6
RUN ./configure CC=mpicc FC=mpif90 CXX=mpic++ --prefix=/opt/hdf5-1.10.6 --enable-build-mode=production --enable-parallel && make -j && make install

#---------------------------------------------------------
# MED 4.0.0
#---------------------------------------------------------

RUN wget http://files.salome-platform.org/Salome/other/med-4.0.0.tar.gz --directory-prefix=/tmp/ \
	&& tar -zxvf /tmp/med-4.0.0.tar.gz -C /tmp/ \
	&& rm -r /tmp/med-4.0.0.tar.gz
RUN mkdir /opt/med-4.0.0
WORKDIR /tmp/med-4.0.0
RUN ./configure CC=mpicc CXX=mpic++ --prefix=/opt/med-4.0.0 --with-med_int=long --disable-python --disable-fortran --with-hdf5=/opt/hdf5-1.10.6 && make -j && make install

#---------------------------------------------------------
# Code Saturne
#---------------------------------------------------------

RUN wget http://www.code-saturne.org/cms/sites/default/files/releases/code_saturne-6.0.2.tar.gz --directory-prefix=/opt/ \
	&& tar -zxvf /opt/code_saturne-6.0.2.tar.gz -C /opt/ \
        && rm -r /opt/code_saturne-6.0.2.tar.gz
RUN mv /opt/code_saturne-6.0.2 /opt/code_saturne-6.0.2_src
RUN mkdir /opt/code_saturne-6.0.2_bld /opt/saturne_tmp
WORKDIR /opt/saturne_tmp
RUN ../code_saturne-6.0.2_src/configure PYTHON=/usr/bin/python3 CC=mpicc FC=mpif90 CXX=mpic++ --prefix=/opt/code_saturne-6.0.2_bld --with-hdf5=/opt/hdf5-1.10.6 --with-med=/opt/med-4.0.0 && make -j && make install

#---------------------------------------------------------
#
# This is probably unsafe
#
# Use at your own risks
#
#---------------------------------------------------------

RUN chmod -R 777 /opt/hdf5-1.10.6/ /opt/med-4.0.0/ /opt/code_saturne-6.0.2_src /opt/code_saturne-6.0.2_bld
RUN echo 'root:rootpwd' | chpasswd
RUN apt-get install -y sudo gnome-terminal
RUN useradd csuser
RUN mkdir /home/csuser
RUN chown csuser /home/csuser
RUN chgrp csuser /home/csuser
RUN echo 'csuser:userpwd' | chpasswd
RUN adduser csuser sudo
USER csuser
ENV HOME /home/csuser
WORKDIR /opt/code_saturne-6.0.2_bld/bin
RUN echo "alias code_saturne="/opt/code_saturne-6.0.2_bld/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 from the host:
#   xhost +local:root
#
# [Linux] When the container is stopped, undo from the host:
#   xhost -local:root
#
#---------------------------------------------------------
The end of the file provides some suggestions for building the image, running the container, and activating the GUI on Linux.

I would appreciate feedback for improvements. I would also appreciate feedback from users running docker on Windows or Mac OS if they are able to activate the GUI.

Kind regards,
Cédric
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Code_Saturne in a docker container

Post by Yvan Fournier »

Hi Cedric,

I have not experimented with Docker for a while, so publishing this is great.

I would add 2 suggestions:
- add CGNS support
- add a debug build

For the second suggestion, adding a second Docker layer may be the best option, so as to avoid having one huger Docker container (layering is a part of Docker which seems interesting but with which I have not played much yet).

For the GUI, we will probably need also to better separate it from the rest of the code (using subprocesses rather than Python import to run the code, build cases, test user function compilation, ...) so as to be able to build just the GUI on one machine, and call the non-graphical parts from that. This is common to Docker containers, WSL installs, some HPC cases, ...

To advance on this, do not hesitate to add a Wiki section on the GitHub page here https://github.com/code-saturne/code_saturne/wiki (I can give you write access if you need).

Best regards,

Yvan
C.FLAG.
Posts: 32
Joined: Fri Apr 08, 2016 2:19 pm

Re: Code_Saturne in a docker container

Post by C.FLAG. »

Hello Yvan,

Here is an updated script with CGNS and a debug build ;

Code: Select all

FROM ubuntu:18.04 as builder

RUN apt-get update -y
RUN apt-get upgrade -y
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
RUN apt-get install -y                             		\
        wget zlib1g-dev                                         \
        vim gedit git gitk                                      \
        gfortran g++ gcc make cmake                             \
        python3 python3-pyqt5                                   \
        pyqt5-dev pyqt5-dev-tools                               \
        openmpi-bin libopenmpi2 libopenmpi-dev
RUN apt-get autoremove
RUN apt-get clean

#---------------------------------------------------------
# hdf5 1.10.6
#---------------------------------------------------------

RUN wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.6/src/hdf5-1.10.6.tar.gz --directory-prefix=/tmp/ \
        && tar -zxvf /tmp/hdf5-1.10.6.tar.gz -C /tmp/ \
        && rm -r /tmp/hdf5-1.10.6.tar.gz
RUN mkdir /opt/hdf5-1.10.6
WORKDIR /tmp/hdf5-1.10.6
RUN ./configure CC=mpicc FC=mpif90 CXX=mpic++ --prefix=/opt/hdf5-1.10.6 --enable-build-mode=production --enable-parallel && make -j && make install
RUN rm -rf /tmp/hdf5-1.10.6

#---------------------------------------------------------
# MED 4.0.0
#---------------------------------------------------------

RUN wget http://files.salome-platform.org/Salome/other/med-4.0.0.tar.gz --directory-prefix=/tmp/ \
	&& tar -zxvf /tmp/med-4.0.0.tar.gz -C /tmp/ \
	&& rm -r /tmp/med-4.0.0.tar.gz
RUN mkdir /opt/med-4.0.0
WORKDIR /tmp/med-4.0.0
RUN ./configure CC=mpicc CXX=mpic++ --prefix=/opt/med-4.0.0 --with-med_int=long --disable-python --disable-fortran --with-hdf5=/opt/hdf5-1.10.6 && make -j && make install
RUN rm -rf /tmp/med-4.0.0

#---------------------------------------------------------
# CGNS 4.1.1
#---------------------------------------------------------

RUN wget https://github.com/CGNS/CGNS/archive/v4.1.1.tar.gz --directory-prefix=/tmp/ \
        && tar -zxvf /tmp/v4.1.1.tar.gz -C /tmp/ \
        && rm  -r /tmp/v4.1.1.tar.gz
RUN mkdir /opt/cgns-4.1.1 /tmp/tmp
WORKDIR /tmp/tmp
RUN cmake -DCMAKE_INSTALL_PREFIX=/opt/cgns-4.1.1 -DCGNS_ENABLE_64BIT=ON -DCGNS_ENABLE_SCOPING=ON -DCGNS_ENABLE_HDF5=ON -DHDF5_NEED_MPI=ON -DHDF5_NEED_ZLIB=ON -DCMAKE_PREFIX_PATH=/opt/hdf5-1.10.6 -DHDF5_INCLUDE_PATH=/opt/hdf5-1.10.6/include -DZLIB_LIBRARY=/usr/lib/x86_64-linux-gnu/libz.so ../CGNS-4.1.1 && make && make install
RUN rm -rf /tmp/CGNS-4.1.1 /tmp/tmp

#---------------------------------------------------------
# Code Saturne, get sources
#---------------------------------------------------------

RUN wget http://www.code-saturne.org/cms/sites/default/files/releases/code_saturne-6.0.2.tar.gz --directory-prefix=/opt/ \
	&& tar -zxvf /opt/code_saturne-6.0.2.tar.gz -C /opt/ \
        && rm -r /opt/code_saturne-6.0.2.tar.gz
RUN mv /opt/code_saturne-6.0.2 /opt/code_saturne-6.0.2_src

#---------------------------------------------------------
# Code Saturne, build
#---------------------------------------------------------

RUN mkdir /opt/code_saturne-6.0.2_bld /opt/saturne_tmp
WORKDIR /opt/saturne_tmp
RUN ../code_saturne-6.0.2_src/configure PYTHON=/usr/bin/python3 CC=mpicc FC=mpif90 CXX=mpic++ --prefix=/opt/code_saturne-6.0.2_bld --with-hdf5=/opt/hdf5-1.10.6 --with-med=/opt/med-4.0.0 --with-cgns=/opt/cgns-4.1.1 && make -j && make install

#---------------------------------------------------------
# Code Saturne, debug build
#---------------------------------------------------------
RUN mkdir /opt/code_saturne-6.0.2_bld_debug
WORKDIR /opt/saturne_tmp
RUN rm -rf *
RUN ../code_saturne-6.0.2_src/configure PYTHON=/usr/bin/python3 CC=mpicc FC=mpif90 CXX=mpic++ CFLAGS='-g' FCFLAGS='-g' --enable-debug --prefix=/opt/code_saturne-6.0.2_bld --with-hdf5=/opt/hdf5-1.10.6 --with-med=/opt/med-4.0.0 --with-cgns=/opt/cgns-4.1.1 && make -j && make install

#---------------------------------------------------------
#
# This is probably unsafe
#
# Use at your own risks
#
#---------------------------------------------------------

RUN chmod -R 777 /opt/hdf5-1.10.6/ /opt/med-4.0.0/ /opt/cgns-4.1.1 /opt/code_saturne-6.0.2_src /opt/code_saturne-6.0.2_bld /opt/code_saturne-6.0.2_bld_debug
RUN echo 'root:rootpwd' | chpasswd
RUN apt-get install -y sudo gnome-terminal
RUN useradd csuser
RUN mkdir /home/csuser
RUN chown csuser /home/csuser
RUN chgrp csuser /home/csuser
RUN echo 'csuser:userpwd' | chpasswd
RUN adduser csuser sudo
USER csuser
ENV HOME /home/csuser
WORKDIR /opt/code_saturne-6.0.2_bld/bin
RUN echo "alias code_saturne=/opt/code_saturne-6.0.2_bld/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
#
#---------------------------------------------------------
I am also not very familiar with Docker, and I suspect the Dockerfile could be significantly improved. I will write a small Wiki section on the github page connected with this post. As it is, I suspect it will not be very convenient to maintain the script: all the folders and library versions are hard coded.

However, this first draft seems to work, and can be used as a basis for additional refinements.

Kind regards,
Cédric
C.FLAG.
Posts: 32
Joined: Fri Apr 08, 2016 2:19 pm

Re: Code_Saturne in a docker container

Post by C.FLAG. »

Re,

Some updated Dockerfile scripts can be found at https://github.com/code-saturne/code_sa ... -container.

Regards,
Cédric
Post Reply