Docker Tips - labordynamicsinstitute/replicability-training GitHub Wiki

Docker can be run on desktops, or on BioHPC, or on CAC RedCloud under certain conditions. A few notes.

Docker images

These images are referenced on the Docker or Singularity command line as:

  • docker [options] dataeditors/stata13:2021-06-09 or docker [options] mathworks/matlab:r2020b
  • singularity pull docker://mathworks/matlab:r2020b

Specific tips

BioHPC

docker on BioHPC is replaced by docker1, see BioHPC documentation

Matlab

License server needs to be accessible (on campus or via VPN). Set the main file and license server:

[email protected]
main="main"
MLM_DOCKER="mathworks/matlab:r2020b"

Possible alternative (with installed Toolboxes):

MLM_DOCKER="registry.codeocean.com/codeocean/matlab:2021b-ubuntu20.04"
docker run -it --rm -e MLM_LICENSE_FILE=$MLM_LICENSE_FILE $MLM_DOCKER

to obtain shell or

docker run -it --rm -e MLM_LICENSE_FILE=$MLM_LICENSE_FILE  \
  -v "$(pwd)":/project \
  -w /project \
  $MLM_DOCKER \
  matlab -nodisplay -r "addpath(genpath('.')); $main"

to run some code contained in the file main.m.

Singularity

Singularity is an alternate mechanisms, and can run Docker images. For instance,

export [email protected]
singularity pull docker://mathworks/matlab:r2020b
singularity run matlab_r2020b.sif

will run Matlab on BioHPC. If enabling the Cornell VPN, this will also work from a workstation/laptop.

Converting Matlab fig images to PNG

Some authors may have generated Matlab fig images. To convert them, set the directory to where the fig files are, and run the following code:

myDir = pwd
convertto = "png"

myFiles = dir(fullfile(myDir,'*.fig')); %gets all fig files in struct
for k = 1:length(myFiles)
  baseFileName = myFiles(k).name;
  [p,baseName,extension]=fileparts(baseFileName);
  fprintf(1, 'Now reading %s\n', baseFileName);
  figs = openfig(baseFileName);
  for K = 1 : length(figs)
      newfilename =  fullfile(baseName + "." + convertto)
      saveas(figs(K), newfilename);
  end
end
exit

(the program is also available in the tools folder)