Main Content

compiler.package.docker

Create a Docker image for files generated by MATLAB Compiler on Linux operating systems

Since R2020b

  • This function is only supported on Linux® operating systems.

  • Only standalone applications can be packaged into Docker® images as of R2020b.

Description

example

compiler.package.docker(results) creates a Docker image for files generated by the MATLAB® Compiler™ using the compiler.build.Results object results. The results object is created by a compiler.build function.

example

compiler.package.docker(results,Name,Value) creates a Docker image using the compiler.build.Results object results and additional options specified as one or more name-value pairs. Options include the build folder, entry point command, and image name.

example

compiler.package.docker(results,'Options',opts) creates a Docker image using the compiler.build.Results object results and additional options specified by a DockerOptions object opts. If you use a DockerOptions object, you cannot specify any other options using name-value pairs.

example

compiler.package.docker(files,filepath,'ImageName',imageName) creates a Docker image using files that are generated by the MATLAB Compiler. The Docker image name is specified by imageName.

example

compiler.package.docker(files,filepath,'ImageName',imageName,Name,Value) creates a Docker image using files that are generated by the MATLAB Compiler. The Docker image name is specified by imageName. Additional options are specified as one or more name-value pairs.

example

compiler.package.docker(files,filepath,'Options',opts) creates a Docker image using files that are generated by the MATLAB Compiler and additional options specified by a DockerOptions object opts. If you use a DockerOptions object, you cannot specify any other options using name-value pairs.

Examples

collapse all

Create a Docker image from a standalone application on a Linux system.

Install and configure Docker on your system.

Create a standalone application using magicsquare.m and save the build results to a compiler.build.Results object.

appFile = fullfile(matlabroot,'extern','examples','compiler','magicsquare.m');
buildResults = compiler.build.standaloneApplication(appFile);

Pass the Results object as an input to the compiler.package.docker function to build the Docker image.

compiler.package.docker(buildResults);

Customize a standalone Docker image using name-value pairs on a Linux system to specify the image name and build directory.

Create a standalone application using magicsquare.m and save the build results to a compiler.build.Results object.

appFile = fullfile(matlabroot,'extern','examples','compiler','magicsquare.m');
buildResults = compiler.build.standaloneApplication(appFile);

Build a Docker image using the Results object and specify additional options as name-value arguments.

compiler.package.docker(buildResults,...
'ImageName','mymagicapp',...
'DockerContext','/home/mluser/Documents/MATLAB/docker');

Customize a Docker image using a DockerOptions object on a Linux system.

Create a standalone application using hello_world.m and save the build results to a compiler.build.Results object.

buildResults = compiler.build.standaloneApplication('hello_world.m');

Create a DockerOptions object to specify additional build options, such as setting a custom image name and disabling the Docker build command.

opts = compiler.package.DockerOptions(buildResults,...
'ImageName','hellodocker');

You can modify property values of an existing DockerOptions object using dot notation. For example, populate the DockerContext folder without calling 'docker build'.

opts.ExecuteDockerBuild = 'Off';

Pass the DockerOptions and Results objects as inputs to the compiler.package.docker function to build the Docker image.

compiler.package.docker(buildResults,'Options',opts);

Create a Docker image using files generated by MATLAB Compiler and specify the image name on a Linux system.

Build a standalone application using the mcc command.

mcc -o runmyapp -m myapp.m

Build the Docker image by passing the generated files to the compiler.package.docker function.

compiler.package.docker('runmyapp','requiredMCRProducts.txt',...
'ImageName','launchapp','EntryPoint','runmyapp');

Customize a Docker image using files generated by MATLAB Compiler and a DockerOptions object on a Linux system.

Create a standalone application using hello_world.m and save the build results to a compiler.build.Results object..

buildResults = compiler.build.standaloneApplication('hello_world.m');

Create a DockerOptions object to specify additional build options, such as the build folder.

opts = compiler.package.DockerOptions(buildResults,...    
'DockerContext','DockerImages')
opts = 

  DockerOptions with properties:

                EntryPoint: 'hello_world'
                 ImageName: 'hello_world'
              RuntimeImage: ''
    AdditionalInstructions: {}
        AdditionalPackages: {}
        ExecuteDockerBuild: on
             ContainerUser: 'appuser'
             DockerContext: './DockerImages'
            VerbosityLevel: 'verbose'

Build the Docker image by passing the generated files to the compiler.package.docker function.

cd helloworldstandaloneApplication

compiler.package.docker('hello_world','requiredMCRProducts.txt',...
'Options',opts);

Input Arguments

collapse all

Build results created by a compiler.build function, specified as a compiler.build.Results object.

Files and folders for installation, specified as a character vector, string scalar, string array, or cell array of strings. These files are typically generated by MATLAB Compiler and can also include any additional files and folders required by the installed application to run. Files generated by MATLAB Compiler in a particular release can be packaged using the compiler.package.docker function of the same release.

Example: 'myDockerFiles/'

Data Types: char | string | cell

Path to the requiredMCRProducts.txt file, specified as a character vector or string scalar. This file is generated by MATLAB Compiler. The path can be relative to the current working directory or absolute.

Example: '/home/mluser/Documents/MATLAB/magicsquare/requiredMCRProducts.txt'

Data Types: char | string

Name of the Docker image. It must comply with Docker naming rules.

Example: 'helloworld'

Data Types: char | string

Docker options, specified as a DockerOptions object.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'ExecuteDockerBuild','on'

Since R2022b

Additional commands to pass to the Docker image, specified as a character vector, a string scalar, or a cell array of character vectors. Commands are added to the Dockerfile and execute during image generation.

For information on valid Dockerfile commands, see https://docs.docker.com/engine/reference/builder/.

Example: 'AdditionalInstructions',{'RUN mkdir /myvol','RUN echo "hello world" > /myvol/greeting','VOLUME /myvol'}

Data Types: char | string

Since R2022b

Additional Ubuntu® 22.04 packages to install into the Docker image, specified as a character vector, a string scalar, or a cell array of character vectors.

Example: 'AdditionalPackages','syslog-ng'

Data Types: char | string

Since R2023b

Name of the Linux user the Docker container will run as, specified as a character vector or a string scalar. The argument must comply with system user naming standards. If the specified user does not exist at the time of creation, a new user will be created with no permissions. If this property is not set, the container will run as the user appuser by default, or the user specified in the FROM command in the Dockerfile.

Example: 'ContainerUser','root'

Data Types: char | string

Path to the build folder where the Docker image is built, specified as a character vector or a string scalar. The path can be relative to the current working directory or absolute.

If no path is specified, the function creates a build folder named ImageNamedocker in the current working directory.

Example: 'DockerContext','/home/mluser/Documents/MATLAB/docker/magicsquaredocker'

Data Types: char | string

The command to be executed at image start-up, specified as a character vector or a string scalar.

Example: 'EntryPoint','exec top -b'

Data Types: char | string

Flag to build the Docker image, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • If you set this property to 'on', then the function will build the Docker image.

  • If you set this property to 'off', then the function will populate the DockerContext folder without calling 'docker build'.

Example: 'ExecuteDockerBuild','Off'

Data Types: logical

Name of the Docker image, specified as a character vector or a string scalar. The name must comply with Docker naming rules. Docker repository names must be lowercase. If the main executable or archive file is named using uppercase letters, then the uppercase letters are replaced with lowercase letters in the Docker image name.

Example: 'ImageName','magicsquare'

Data Types: char | string

Since R2023b

Name of the MATLAB Runtime image, specified as a character vector or a string scalar. You can use the compiler.runtime.createDockerImage (MATLAB Compiler SDK) function to create a custom MATLAB Runtime image that can run multiple applications. If not specified, MATLAB Compiler generates a selective MATLAB Runtime image that can only run the packaged application.

Example: 'RuntimeImage','mcrimage'

Data Types: char | string

Since R2023b

Output verbosity level, specified as one of the following options:

  • 'verbose' (default) — Display all screen output, including Docker output that occurs from the commands 'docker pull' and 'docker build'.

  • 'concise' — Display progress information without Docker output

  • 'none' — Do not display output.

Example: 'VerbosityLevel','concise'

Data Types: char | string

Version History

Introduced in R2020b