Skip to content

Making a Docker Image

aechavez edited this page Apr 16, 2022 · 5 revisions

Docker and Singularity are platforms that allow us to use containers/images of software setups. The basic idea is that you create a working environment locally where ldmx-sw is installed and running with all its dependencies. You then bundle that setup into an image that gets saved and pushed to be used in a container elsewhere. Included here are instructions for installing ldmx-analysis. You almost certainly do not need to do this section as the group has made our own python-based analysis scripts.

Install Software Locally Using Docker

  1. Install Docker if you do not have it already -- https://docs.docker.com/get-docker/ -- and make a Docker account.
  2. Install the version of ldmx-sw that you need (change the GitHub branch/tag).
git clone -b <insert branch name here> --recursive https://github.com/LDMX-Software/ldmx-sw.git
source ldmx-sw/scripts/ldmx-env.sh
ldmx pull [dev/pro/local] <insert tag name here>      #optional, changes container used to install ldmx-sw
cd ldmx-sw; mkdir build; cd build;
ldmx cmake ..
ldmx make install

If you are trying to change the container used to install ldmx-sw and you get an error with the ldmx pull line, look into the ldmx-env.sh file. It's possible the syntax has just changed a bit.

OPTIONAL/OBSOLETE: Install the version of ldmx-analysis that works with the version of ldmx-sw you have

git clone https://github.com/LDMX-Software/ldmx-analysis.git
git reset --hard <insert_commit_hash_number_here> ***optional***
git checkout <insert branch name here> ***optional***
cd ldmx-analysis; git submodule update —init —recursive [added the submodule update to handle “could not find load file: BuildMacros”]
mkdir build; cd build
ldmx cmake ..
ldmx make install
  1. Make any changes you need to ldmx-sw. Changes should be tested by rebuilding ldmx-sw.
#in the ldmx-sw/build/ directory
ldmx cmake ..
ldmx make install

Push Compiled Software as an Image to Docker Hub

  1. Make Dockerfile in the directory containing ldmx-sw. The contents of the file should match below. Check that the ARG DEV_TAG is set to the tag you used to install ldmx-sw.
ARG DEV_TAG=latest
FROM ldmx/dev:${DEV_TAG}

# install ldmx-sw into the container at /usr/local
COPY . /code
RUN rm -rf /code/ldmx-sw/build &&\
    mkdir /code/ldmx-sw/build &&\
    ./home/ldmx.sh /code/ldmx-sw/build cmake -DCMAKE_INSTALL_PREFIX=/usr/local .. &&\
    ./home/ldmx.sh /code/ldmx-sw/build make install &&\
    rm -rf code

COPY ./ldmx-sw/scripts/docker_entrypoint.sh /home/docker_entrypoint.sh
RUN chmod 755 /home/docker_entrypoint.sh
ENTRYPOINT ["/home/docker_entrypoint.sh"]
  1. Build and then push the Docker image to Docker Hub.
docker build . -t <docker_user_name>/<docker_repo_name>:<tag_name>
docker push <docker_user_name>/<docker_repo_name>:<tag_name>