-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
136 lines (114 loc) · 6.23 KB
/
Dockerfile
File metadata and controls
136 lines (114 loc) · 6.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# This Dockerfile is modification of https://github.com/mathworks-ref-arch/matlab-dockerfile (Copyright 2019-2024 The MathWorks, Inc.)
# There is a flexibility in the way the image is build and you can edit parameters according to your needs.
# Since it's matlab, you need at least a license to run it locally
# You need to have access to a matlab license server if you want to run this in a non interactive fashion (e.g. on clusters running SLURM without interaction)
# Here is an example docker build command with the optional build arguments.
# docker build --build-arg MATLAB_RELEASE=r2024a
# --build-arg MATLAB_PRODUCT_LIST="MATLAB Deep_Learning_Toolbox Symbolic_Math_Toolbox"
# --build-arg MATLAB_INSTALL_LOCATION="/opt/matlab/R2024a"
# --build-arg LICENSE_SERVER=12345@hostname.com
# -t my_matlab_image_name .
# To specify which MATLAB release to install in the container, edit the value of the MATLAB_RELEASE argument.
# Use lowercase to specify the release, for example: ARG MATLAB_RELEASE=r2021b
# Note the matlab version should be matching the license server last update.
## SUGGESTED USE:
# sudo docker build --build-arg LICENSE_SERVER=port@servername -t my_matlab_image_name .
# Optionally you can add (--platform linux/amd64 to specify your platform) (--progress=plain for debug logging)
# sudo docker run --init --rm my_matlab_image_name
## Default parameters, note this is the minimal set of toolboxes to run monalisa
ARG MATLAB_RELEASE=r2024a
# Specify the list of products to install into MATLAB.
ARG MATLAB_PRODUCT_LIST="MATLAB Statistics_and_Machine_Learning_Toolbox Curve_Fitting_Toolbox Image_Processing_Toolbox Optimization_Toolbox Signal_Processing_Toolbox Robotics_System_Toolbox"
# Specify MATLAB Install Location.
ARG MATLAB_INSTALL_LOCATION="/opt/matlab/${MATLAB_RELEASE}"
# Specify license server information using the format: port@hostname
ARG LICENSE_SERVER
# When you start the build stage, this Dockerfile by default uses the Ubuntu-based matlab-deps image.
# To check the available matlab-deps images, see: https://hub.docker.com/r/mathworks/matlab-deps
FROM mathworks/matlab-deps:r2024a
# Declare build arguments to use at the current build stage.
ARG MATLAB_RELEASE
ARG MATLAB_PRODUCT_LIST
ARG MATLAB_INSTALL_LOCATION
ARG LICENSE_SERVER
ARG OUTPUT_DIR="/usr/src/app/output"
# Install mpm dependencies.
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install --no-install-recommends --yes \
wget \
unzip \
ca-certificates \
gcc-11 \
g++-11 \
git \
expect \
libgtk2.0-0 \
# build-essential \
make \
&& update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 \
&& update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100 \
&& apt-get clean \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/*
# Add "matlab" user and grant sudo permission.
RUN adduser --shell /bin/bash --disabled-password --gecos "" matlab \
&& echo "matlab ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/matlab \
&& chmod 0440 /etc/sudoers.d/matlab
# Set user and work directory.
# USER root
# RUN apt-get update && apt-get install -y libgtk2.0-0 build-essential
USER matlab
WORKDIR /home/matlab
# Run mpm to install MATLAB in the target location and delete the mpm installation afterwards.
# If mpm fails to install successfully, then print the logfile in the terminal, otherwise clean up.
# Pass in $HOME variable to install support packages into the user's HOME folder.
RUN wget -q https://www.mathworks.com/mpm/glnxa64/mpm \
&& chmod +x mpm \
&& sudo HOME=${HOME} ./mpm install \
--release=${MATLAB_RELEASE} \
--destination=${MATLAB_INSTALL_LOCATION} \
--products ${MATLAB_PRODUCT_LIST} \
|| (echo "MPM Installation Failure. See below for more information:" && cat /tmp/mathworks_root.log && false) \
&& sudo rm -rf mpm /tmp/mathworks_root.log \
&& sudo ln -s ${MATLAB_INSTALL_LOCATION}/bin/matlab /usr/local/bin/matlab
# wanted to remove the `sudo` above, but error about permission occurred, so added them back
# Note: Uncomment one of the following two ways to configure the license server.
# Option 1. Specify the host and port of the machine that serves the network licenses
# if you want to store the license information in an environment variable. This
# is the preferred option. You can either use a build variable, like this:
# --build-arg LICENSE_SERVER=27000@MyServerName or you can specify the license server
# directly using: ENV MLM_LICENSE_FILE=27000@flexlm-server-name
ENV MLM_LICENSE_FILE=$LICENSE_SERVER
# Option 2. Alternatively, you can put a license file into the container.
# Enter the details of the license server in this file and uncomment the following line.
# COPY network.lic ${MATLAB_INSTALL_LOCATION}/licenses/
# The following environment variables allow MathWorks to understand how this MathWorks
# product (MATLAB Dockerfile) is being used. This information helps us make MATLAB even better.
# Your content, and information about the content within your files, is not shared with MathWorks.
# To opt out of this service, delete the environment variables defined in the following line.
# To learn more, see the Help Make MATLAB Even Better section in the accompanying README:
# https://github.com/mathworks-ref-arch/matlab-dockerfile#help-make-matlab-even-better
ENV MW_DDUX_FORCE_ENABLE=true MW_CONTEXT_TAGS=MATLAB:DOCKERFILE:V1
# Set the working directory inside the container
WORKDIR /usr/src/app
# Copy the entire local monalisa directory into the container
COPY . /usr/src/app
# Yiwei: add this line for changing the permission.
USER root
RUN chmod -R ugo+x /usr/src/app
# Set the working directory to the folder containing your script
WORKDIR /usr/src/app/examples/scripts
# DEBUG LOGGING: Check if the directory /usr/src/app/src/bmFourierN exists
RUN if [ -d "/usr/src/app/src/fourierN" ]; then \
echo "Directory /usr/src/app/src/fourierN exists"; \
else \
echo "Directory /usr/src/app/src/fourierN does not exist"; \
exit 1; \
fi
ENTRYPOINT ["matlab"]
# I am using root otherwise I encountered permission errors, not sure it's safe (INITIAL)
# Yiwei: comment it, avoid root permission...
USER root
# Compile c++ code
CMD ["matlab", "-batch", "testDocker"]