Main Content

compiler.package.docker

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

Description

example

Caution

This function is only supported on Linux® operating systems.

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);

The Results object is passed as an input to the compiler.package.docker function to build the docker image.

compiler.package.docker(buildResults);

Customize a standalone application 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 the docker image using the Results object and specify additional options as name-value pair 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 the image name.

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

The DockerOptions and Results objects are passed 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 the 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 the MATLAB Compiler and a DockerOptions object on a Linux system.

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

buildResults = compiler.build.standaloneApplication('helloworld.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: 'helloworld'
    ExecuteDockerBuild: on
             ImageName: 'helloworld'
         DockerContext: './DockerImages'

You can modify property values of an existing DockerOptions object using dot notation.

opts.ExecuteDockerBuild = 'Off';

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

cd helloworldstandaloneApplication

compiler.package.docker('helloworld','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 the MATLAB Compiler product and can also include any additional files and folders required by the installed application to run. Files generated by the MATLAB Compiler product 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 the MATLAB Compiler product. 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: 'hello-world'

Data Types: char | string

Docker options, specified as a DockerOptions object.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'ExecuteDockerBuild','on'

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, a build folder named ImageNamedocker will be created 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

Limitations

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

Introduced in R2020b