|
1 | 1 | # Copyright 2020 The MathWorks, Inc. |
2 | 2 |
|
| 3 | +# Argument shared across multi-stage build to hold location of installed MATLAB |
| 4 | +ARG BASE_ML_INSTALL_LOC=/tmp/matlab-install-location |
| 5 | + |
3 | 6 | # Replace "matlab" with the Docker image that contains MATLAB |
4 | | -# MATLAB should be installed at /usr/local/MATLAB or other changes will need |
5 | | -# to be made to this Dockerfile |
| 7 | +# MATLAB should be available on the path in the Docker image |
6 | 8 | FROM matlab AS matlab-install-stage |
| 9 | +ARG BASE_ML_INSTALL_LOC |
| 10 | + |
| 11 | +# Run code to locate a MATLAB install in the base image and softlink |
| 12 | +# to BASE_ML_INSTALL_LOC for a latter stage to copy |
| 13 | +RUN export ML_INSTALL_LOC=$(which matlab) \ |
| 14 | + && if [ ! -z "$ML_INSTALL_LOC" ]; then \ |
| 15 | + ML_INSTALL_LOC=$(dirname $(dirname $(readlink -f ${ML_INSTALL_LOC}))); \ |
| 16 | + echo "soft linking: " $ML_INSTALL_LOC " to" ${BASE_ML_INSTALL_LOC}; \ |
| 17 | + ln -s ${ML_INSTALL_LOC} ${BASE_ML_INSTALL_LOC}; \ |
| 18 | + elif [ $BASE_ML_INSTALL_LOC = '/tmp/matlab-install-location' ]; then \ |
| 19 | + echo "MATLAB was not found in your image."; exit 1; \ |
| 20 | + else \ |
| 21 | + echo "Proceeding with user provided path to MATLAB installation: ${BASE_ML_INSTALL_LOC}"; \ |
| 22 | + fi |
7 | 23 |
|
8 | 24 | FROM jupyter/base-notebook |
| 25 | +ARG BASE_ML_INSTALL_LOC |
9 | 26 |
|
10 | 27 | # Switch to root user |
11 | 28 | USER root |
12 | 29 |
|
| 30 | +# Copy MATLAB install from supplied Docker image |
| 31 | +COPY --from=matlab-install-stage ${BASE_ML_INSTALL_LOC} /usr/local/MATLAB |
| 32 | + |
| 33 | +# Put MATLAB on the PATH |
| 34 | +RUN ln -s /usr/local/MATLAB/bin/matlab /usr/local/bin/matlab |
| 35 | + |
13 | 36 | # Install MATLAB dependencies |
14 | 37 | # Reference: https://github.com/mathworks-ref-arch/container-images/tree/master/matlab-deps |
15 | 38 | RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install --no-install-recommends -y \ |
@@ -71,12 +94,6 @@ RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install - |
71 | 94 | && apt-get clean \ |
72 | 95 | && rm -rf /var/lib/apt/lists/* |
73 | 96 |
|
74 | | -# Put MATLAB on the PATH |
75 | | -RUN ln -s /usr/local/MATLAB/bin/matlab /usr/local/bin/matlab |
76 | | - |
77 | | -# Copy MATLAB install from supplied Docker image |
78 | | -COPY --from=matlab-install-stage /usr/local/MATLAB /usr/local/MATLAB |
79 | | - |
80 | 97 | # Switch back to notebook user |
81 | 98 | USER $NB_USER |
82 | 99 |
|
|
0 commit comments