Maxwell : Creating a Docker image

As an example let us consider how centos_mpi image is created.

 

  1. Create a Dockerfile

    Dockerfile
    # The base image. If not present, will be loaded from Dockerhub automatically
    FROM centos:7
    
    #
    MAINTAINER Sergey Yakubov <sergey.yakubov@desy.de>
    
    # RUN command executes a bash command. Every command creates a layer in a union
    # filesystem which are then put one on top of other to get a final image.
    # Several commands can be joined with && to avoid too many filesystem layers
    
    # install ssh, set pam parameter
    RUN yum install -y openssh-clients openssh-server && ssh-keygen -A && \
        sed -i 's/required\(.*pam_loginuid\)/optional\1/' /etc/pam.d/sshd
    
    
    # install infiniband
    RUN yum install -y ibibverbs-utils libibverbs-devel libibverbs-devel-static \
    	libmlx4 libmlx5 ibutils libibcm libibcommon libibmad libibumad rdma \
    	librdmacm-utils librdmacm-devel librdmacm libibumad-devel perftest
    
    # install mpi
    RUN yum install -y openmpi openmpi-devel make
    # needed for current package version to avoid error messages
    RUN echo "mtl = ^ofi" >> /etc/openmpi-x86_64/openmpi-mca-params.conf
    
    # ENV command sets environment variable which can be accessed when container is started
    ENV PATH=/usr/lib64/openmpi/bin:$PATH
    ENV LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH
    
    # add path to mpi to start-up scripts
    RUN echo "export PATH=/usr/lib64/openmpi/bin:${PATH}" > /etc/profile.d/scripts-path.sh && \
    	echo "export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH" >> /etc/profile.d/scripts-path.sh &&\
    	chmod 755 /etc/profile.d/scripts-path.sh
    
    

     

     

  2.  As soon as this files are ready we can build docker image (called from the directory where the files are).

    $ docker build -t <your Dockerhub name>/centos_mpi .
  3. We can now upload the image into Docker Hub

    $ docker push <your Dockerhub name>/centos_mpi

     

     

This was an example for centos_mpi. Actually, you would start from this image, so the first line in your Dockerfile will be FROM <your Dockerhub name>/centos_mpi . Then you install the packages you need and applications you will later run.