mathworks-ref-arch/matlab-dockerfile

Custom image build generated root-owned files in /home/matlab

Closed this issue · 3 comments

I successfully built a custom image using a product list:

$ export MATLAB_PRODUCT_LIST="MATLAB Financial_Toolbox Parallel_Computing_Toolbox MATLAB_Coder MATLAB_Compiler MATLAB_Compiler_SDK MATLAB_Parallel_Server MATLAB_Production_Server MATLAB_Report_Generator MATLAB_Test MATLAB_Web_App_Server"

$ docker build --build-arg MATLAB_PRODUCT_LIST="${MATLAB_PRODUCT_LIST}" -t custom-matlab:R2024b .
[+] Building 254.0s (9/9) FINISHED                                                                                docker:default
 => [internal] load build definition from Dockerfile                                                                        0.0s
 => => transferring dockerfile: 4.34kB                                                                                      0.0s
 => [internal] load .dockerignore                                                                                           0.0s
 => => transferring context: 2B                                                                                             0.0s
 => [internal] load metadata for docker.io/mathworks/matlab-deps:R2024b                                                     1.0s
 => [1/5] FROM docker.io/mathworks/matlab-deps:R2024b@sha256:3747753686c2cfeee04c9c7558787db93f608a034c6d3c44b14e750b12b06  0.0s
 => [2/5] RUN export DEBIAN_FRONTEND=noninteractive     && apt-get update     && apt-get install --no-install-recommends -  9.5s
 => [3/5] RUN adduser --shell /bin/bash --disabled-password --gecos "" matlab     && echo "matlab ALL=(ALL) NOPASSWD: ALL"  0.6s
 => [4/5] WORKDIR /home/matlab                                                                                              0.0s
 => [5/5] RUN wget -q https://www.mathworks.com/mpm/glnxa64/mpm     && chmod +x mpm     && sudo HOME=${HOME} ./mpm insta  175.9s
 => exporting to image                                                                                                     66.9s
 => => exporting layers                                                                                                    66.9s
 => => writing image sha256:7643b414569ee9733d02cccaea29932d631aa42837f463b7cd6625abfb7e615d                                0.0s
 => => naming to docker.io/library/custom-matlab:R2024b                                                                     0.0s

However, the resulting image contained a root-owned /home/matlab/.matlab directory, causing a MATLAB error:

                                                     < M A T L A B (R) >
                                           Copyright 1984-2024 The MathWorks, Inc.
                                      R2024b Update 1 (24.2.0.2740171) 64-bit (glnxa64)
                                                     September 20, 2024


To get started, type doc.
For product information, visit www.mathworks.com.

>> Warning: Unable to create preferences folder in /home/matlab/.matlab/R2024b. Preferences folder location must be writable. Using a temporary preferences folder for this MATLAB session. See the <a href="matlab: helpview([docroot
'/matlab/helptargets.map'],'matlabenvironment_prefdir_location')">preferences documentation</a> for more details.
>> exit

The /home/matlab/.matlab contents are trivial.

Reading the Dockerfile, I'm guessing it was mpm when running as USER matlab, in WORKDIR /home/matlab, but as root via sudo [...] ./mpm install .... I've never used mpm, nor many of the products I installed, so I don't have a guess which specific package created the files.

$ docker run --rm -it --entrypoint /bin/bash custom-matlab:R2024b
matlab@9741fd944aa9:~$ ls -al /home/matlab/
total 28
drwxr-x--- 1 matlab matlab 4096 Nov  8 04:51 .
drwxr-xr-x 1 root   root   4096 Nov  8 04:48 ..
-rw-r--r-- 1 matlab matlab  220 Nov  8 04:48 .bash_logout
-rw-r--r-- 1 matlab matlab 3771 Nov  8 04:48 .bashrc
drwxr-xr-x 3 root   root   4096 Nov  8 04:48 .matlab
-rw-r--r-- 1 matlab matlab  807 Nov  8 04:48 .profile
matlab@9741fd944aa9:~$ ls -l .matlab/
total 4
drwxr-xr-x 2 root root 4096 Nov  8 04:48 R2025a
matlab@9741fd944aa9:~$ ls -l .matlab/R2025a/
total 4
-rw-r--r-- 1 root root 0 Nov  8 04:48 creation.timestamp
-rw-r--r-- 1 root root 1 Nov  8 04:48 migratePref.txt
matlab@0c452b2cb194:~$ cat ~/.matlab/R2025a/migratePref.txt
T

I worked around it with a hack to the Dockerfile to repair the ownership:

# Fix root owned preferences directory
USER root
RUN chown -R matlab:matlab /home/matlab/.matlab
USER matlab

Hi @richardkmichael

Thank you for reporting this issue.

The issue is with the 2024.3 release of mpm, and you can work around this by setting the environment variable MW_SPROOT_SETTINGSXML=1 before the mpm install command as shown in this Dockerfile

We will keep this issue open until a future release of MPM fixes this.

Hope this helps, and once again thank you for the detailed report!

Hi @richardkmichael
An update for the MATLAB Package Manager (version 2024.4) has been released which fixes this bug.

Thank you for reporting this!

reference: a345307