|
| 1 | +# Create a Windows Container Image for MATLAB |
| 2 | + |
| 3 | +This repository shows you how to build and customize a Windows® Docker® container for MATLAB® and its toolboxes, using the [MATLAB Package Manager](https://github.com/mathworks-ref-arch/matlab-dockerfile/blob/main/MPM.md) (`mpm`) and [MATLAB Batch Licensing (`matlab-batch`)](../alternates/non-interactive/MATLAB-BATCH.md). You can use this container image as a scalable and reproducible method to deploy and test your MATLAB code on a Windows platform. |
| 4 | + |
| 5 | +Use this Dockerfile if you have a MATLAB batch licensing token to license MATLAB in your container. The MATLAB batch licensing project is still in the pilot phase. To inquire about eligibility requirements, fill out this form on the MathWorks® website: [Batch Licensing Pilot Eligibility](https://www.mathworks.com/support/batch-tokens.html). |
| 6 | + |
| 7 | +### Requirements |
| 8 | +* MATLAB Batch Licensing Token. For more information, see [Use MATLAB Batch Licensing](../alternates/non-interactive/MATLAB-BATCH.md#matlab-batch-licensing-token). |
| 9 | +* Docker Desktop for Windows® (Windows 10 or later) or a Windows Server® build host (Windows Server 2016 or later). |
| 10 | + |
| 11 | +## Build Instructions |
| 12 | +### Get the Dockerfile |
| 13 | + |
| 14 | +Access this Dockerfile either by directly downloading this repository from GitHub®, or by cloning this repository and then navigating to the appropriate subfolder. |
| 15 | +```bash |
| 16 | +git clone https://github.com/mathworks-ref-arch/matlab-dockerfile.git |
| 17 | +cd matlab-dockerfile/windows/ |
| 18 | +``` |
| 19 | + |
| 20 | +### Build and Run Docker Image |
| 21 | + |
| 22 | +Build container with a name and tag of your choice. |
| 23 | +```powershell |
| 24 | +docker build -t matlab-on-windows:R2025a . |
| 25 | +``` |
| 26 | +This [Dockerfile](./Dockerfile) defaults to building a Windows container for MATLAB R2025a. The Dockerfile is based on the Windows base image which contains the full Windows API set. For details, see the documentation on DockerHub for [Windows base image](https://hub.docker.com/r/microsoft/windows). |
| 27 | + |
| 28 | +Test the container by running an example MATLAB command, such as `ver`. The entry point of the container is PowerShell. |
| 29 | +```powershell |
| 30 | +docker run --rm matlab-on-windows:R2025a matlab-batch "-licenseToken" "[email protected]::encodedToken" "ver" |
| 31 | +``` |
| 32 | +For more information on running the container, see [Run the Container](#run-the-container). |
| 33 | + |
| 34 | +## Customize the Image |
| 35 | + |
| 36 | +By default, the [Dockerfile](Dockerfile) installs the latest available MATLAB release without any additional toolboxes or products, as well as the latest version of [**matlab-batch**](../alternates/non-interactive/MATLAB-BATCH.md). |
| 37 | + |
| 38 | +Use the options below to customize your build. |
| 39 | + |
| 40 | +### Customize MATLAB Release and MATLAB Product List |
| 41 | +The [Dockerfile](Dockerfile) supports these Docker build-time variables: |
| 42 | + |
| 43 | +| Argument Name | Default Value | Description | |
| 44 | +|---|---|---| |
| 45 | +| [MATLAB_RELEASE](#build-an-image-for-a-different-release-of-matlab) | R2025a | MATLAB release to install, for example, `R2023b`. | |
| 46 | +| [MATLAB_PRODUCT_LIST](#build-an-image-with-a-specific-set-of-products) | MATLAB | Space-separated list of products to install. For help specifying the products to install, see the "products" input argument on the [documentation page for the mpm install function](https://www.mathworks.com/help/install/ug/mpminstall.html). For example: `MATLAB Simulink Deep_Learning_Toolbox Fixed-Point_Designer` | |
| 47 | + |
| 48 | +Use these arguments with the `docker build` command to customize your image. |
| 49 | +Alternatively, the default values for these arguments can be changed directly in the [Dockerfile](Dockerfile). |
| 50 | + |
| 51 | +> Note: MATLAB is installed to `C:\MATLAB` in the Windows container because the default `matlabroot` location can cause issues with compiler products. For details about the issues, see [Build Process Support for File and Folder Names](https://www.mathworks.com/help/coder/ug/enable-build-process-for-folder-names-with-spaces.html) and this [MATLAB Answer](https://www.mathworks.com/matlabcentral/answers/95399-why-is-the-build-process-failing-with-error-code-nmake-fatal-error-u1073-don-t-know-how-to-make). Additionally, you cannot use the suggested 8.3 short file names as a workaround because it is not supported in Windows containers. For details, see this [GitHub issue](https://github.com/microsoft/Windows-Containers/issues/507). |
| 52 | +
|
| 53 | +### Build an Image for a Different Release of MATLAB |
| 54 | + |
| 55 | +For example, to build an image for MATLAB R2021b, use this command. |
| 56 | +```powershell |
| 57 | +docker build --build-arg MATLAB_RELEASE=R2021b -t matlab-windows:R2021b . |
| 58 | +``` |
| 59 | + |
| 60 | +For supported releases, see [MATLAB Batch Licensing support](../alternates/non-interactive/MATLAB-BATCH.md#limitations). |
| 61 | + |
| 62 | +### Build an Image with a Specific Set of Products |
| 63 | + |
| 64 | +For example, to build an image with MATLAB and the Statistics and Machine Learning Toolbox™, use this command. |
| 65 | +```powershell |
| 66 | +docker build --build-arg MATLAB_PRODUCT_LIST="MATLAB Statistics_and_Machine_Learning_Toolbox" -t matlab-stats-windows:R2025a . |
| 67 | +``` |
| 68 | + |
| 69 | +## Run the Container |
| 70 | +To start a container and run MATLAB with a MATLAB batch licensing token, open a Windows PowerShell and enter this command: |
| 71 | +```powershell |
| 72 | +# Start MATLAB, display 'hello world', and exit. |
| 73 | +docker run --rm matlab-on-windows:R2025a matlab-batch -licenseToken '[email protected]::encodedToken' '\"disp(''hello world'')\"' |
| 74 | +``` |
| 75 | +Note that you must use the rules for using single and double quotation marks in PowerShell. For details, see [about quoting rules](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_quoting_rules). |
| 76 | + |
| 77 | +Alternatively, you can run a script `myscript.m` containing MATLAB code: |
| 78 | + |
| 79 | +```powershell |
| 80 | +# Launch MATLAB, run `myscript.m` and exit: |
| 81 | +docker run --mount "type=bind,src=C:\scripts,target=C:\pwd" --workdir "C:\pwd" --rm matlab-on-windows:R2025a matlab-batch -licenseToken '[email protected]::encodedToken' 'myscript' |
| 82 | +``` |
| 83 | + |
| 84 | +You can also set your MATLAB batch licensing token at the container level by setting the `MLM_LICENSE_TOKEN` environment variable. For example: |
| 85 | + |
| 86 | +```powershell |
| 87 | +# Start MATLAB, display 'hello world', and exit. |
| 88 | +docker run -e MLM_LICENSE_TOKEN='[email protected]::encodedToken' --rm matlab-on-windows:R2025a matlab-batch '\"disp(''hello world'')\"' |
| 89 | +``` |
| 90 | + |
| 91 | +## Feedback |
| 92 | +We encourage you to try this repository with your environment and provide feedback. If you encounter a technical issue or have an enhancement request, create an issue [here](https://github.com/mathworks-ref-arch/matlab-dockerfile/issues). |
| 93 | + |
| 94 | +--- |
| 95 | +Copyright 2025 The MathWorks, Inc. |
0 commit comments