Main Content

compiler.package.DockerOptions

Create a docker options object

Description

example

Caution

This function is only supported on Linux® operating systems.

opts = compiler.package.DockerOptions(results) creates a DockerOptions object opts using the compiler.build.Results object results. The Results object is created by a compiler.build function. The DockerOptions object is passed as an input to the compiler.package.docker function to specify build options.

example

opts = compiler.package.DockerOptions(results,Name,Value) creates a DockerOptions object opts 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

opts = compiler.package.DockerOptions('ImageName',imageName) creates a default DockerOptions object with the image name specified by imageName.

example

opts = compiler.package.DockerOptions('ImageName',imageName,Name,Value) creates a default DockerOptions object with the image name specified by imageName and additional options specified as one or more name-value pairs.

Examples

collapse all

Create a DockerOptions object using the build results from a standalone application on a Linux 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);

Create a DockerOptions object using the build results from the compiler.build.standaloneApplication function.

opts = compiler.package.DockerOptions(buildResults);

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

opts.DockerContext = 'myDockerFiles';

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

Customize a DockerOptions object using name-value pairs to specify the image name and build folder.

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

Create a DockerOptions object using the build results from the compiler.build.standaloneApplication function and additional options specified as name-value pairs.

opts = compiler.package.DockerOptions(buildResults,...
    'DockerContext','Docker/MagicSquare',...
    'ImageName','magic-square-');
opts = 

  DockerOptions with properties:

            EntryPoint: 'magicsquare'
    ExecuteDockerBuild: on
             ImageName: 'magic-square-'
         DockerContext: './Docker/MagicSquare/magic-square-docker'

Create a default DockerOptions object to specify the image name.

Create a DockerOptions object.

opts = compiler.package.DockerOptions('ImageName','helloworld')
opts = 

  DockerOptions with properties:

            EntryPoint: ''
    ExecuteDockerBuild: on
             ImageName: 'helloworld'
         DockerContext: './helloworlddocker'

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

opts.ExecuteDockerBuild = 'Off';
opts = 

  DockerOptions with properties:

            EntryPoint: ''
    ExecuteDockerBuild: off
             ImageName: 'helloworld'
         DockerContext: './helloworlddocker'

Create a DockerOptions object that specifies the image name, build folder, and entry point command.

Create a DockerOptions object.

opts = compiler.package.DockerOptions('ImageName','myapp-',...
    'DockerContext','Docker/MyDockerApp',...
    'EntryPoint',"exec top -b")
opts = 

  DockerOptions with properties:

            EntryPoint: 'exec top -b'
    ExecuteDockerBuild: on
             ImageName: 'myapp-'
         DockerContext: './Docker/MyDockerApp'

Input Arguments

collapse all

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

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

Example: 'hello-world'

Data Types: char | string

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

Output Arguments

collapse all

Docker image build options, returned as a DockerOptions object.

Limitations

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

Introduced in R2020b