DockerContainer

Description

The DockerContainer object represents a Docker container configuration and provides methods for starting/stopping and running/executing commands in the container. Its parent object has to be a DockerService which implements the required mechanisms for the container operations and initially starts all enabled containers.

› Inherits:Object

Properties

arguments

This property holds a list of arguments which to pass to the executable specified by entryPoint.

This property was introduced in InCore 2.6.

› Type:StringList
› Signal:argumentsChanged()
› Attributes:Writable

cleanUpAtExit

This property holds whether to automatically remove the container after it has exited and restartPolicy is set to DockerContainer.NoRestart.

› Type:Boolean
› Default:true
› Signal:cleanUpAtExitChanged()
› Attributes:Writable

cleanUpAtStart

This property holds whether to automatically remove a potentially existing instance of the container identified by name before starting. If an instance with the same name exists, the container can’t be started otherwise.

› Type:Boolean
› Default:true
› Signal:cleanUpAtStartChanged()
› Attributes:Writable

enabled

This property holds whether the container is enabled, i.e. can be started. When enabled the container is started by DockerService automatically on start.

› Type:Boolean
› Default:true
› Signal:enabledChanged()
› Attributes:Writable

entryPoint

This property holds an alternative entrypoint, i.e. command to execute for running the container. See the official Docker documentation on ENTRYPOINT for details.

› Type:String
› Signal:entryPointChanged()
› Attributes:Writable

environment

This property holds a list of environment variables and their values for the container. See the official Docker documentation on environment variables for details.

› Type:StringList
› Signal:environmentChanged()
› Attributes:Writable

error

This property holds the most recently occurred error or DockerContainer.NoError if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() signal to detect multiple occurrences of the same error.

› Type:Error
› Signal:errorChanged()
› Attributes:Readonly

errorString

This property holds the current human readable error string corresponding to the current value in the error property. It may include additional information such as failure reasons or locations.

› Type:String
› Signal:errorStringChanged()
› Attributes:Readonly

hostname

This property holds the hostname to assign the Docker container. This allows other containers in the same network to connect to services in this container by hostname instead of IP address. See the official Docker documentation on containers and hostnames for details.

› Type:String
› Signal:hostnameChanged()
› Attributes:Writable

image

This property holds the name of the image and an optional version tag to run in the container. See the official Docker documentation on images for details.

› Type:String
› Signal:imageChanged()
› Attributes:Writable

mounts

This property holds a list of Docker mounts (i.e. local directories) which to provide in the container. See the DockerMount documentation for details.

› Type:List<DockerMount>
› Signal:mountsChanged()
› Attributes:Readonly

name

This property holds the name of the container. See the official Docker documentation on container names for details.

› Type:String
› Signal:nameChanged()
› Attributes:Writable

networkMode

This property holds the network mode for the container. See DockerContainer.NetworkMode and the official Docker documentation on networking for details.

This property was introduced in InCore 2.0.

› Type:NetworkMode
› Default:DockerContainer.Bridge
› Signal:networkModeChanged()
› Attributes:Writable

networks

This property holds a list of Docker networks which to connect the container to if networkMode is set to DockerContainer.Bridge. See the DockerNetwork documentation for details.

› Type:List<DockerNetwork>
› Signal:networksChanged()
› Attributes:Readonly

ports

This property holds a list of ports to forward from the container to the host interface. See the official Docker documentation on incoming ports for details.

› Type:StringList
› Signal:portsChanged()
› Attributes:Writable

restartPolicy

This property holds a setting which specifies how and when a container should be restarted on exit. See the DockerContainer.RestartPolicy enumeration for details.

› Type:RestartPolicy
› Default:DockerContainer.RestartOnFailure
› Signal:restartPolicyChanged()
› Attributes:Writable

running

This property holds whether the container is currently running. This property is updated by start() and stop().

› Type:Boolean
› Default:false
› Signal:runningChanged()
› Attributes:Readonly

seccompProfile

This property holds the path to a custom seccomp profile file. This allows to customize the system calls which the container is allowed to use. See the official Docker documentation on seccomp security profiles for details.

This property was introduced in InCore 2.1.

› Type:String
› Signal:seccompProfileChanged()
› Attributes:Writable

volumes

This property holds a list of Docker volumes which to provide in the container. See the DockerVolume documentation for details.

› Type:List<DockerVolume>
› Signal:volumesChanged()
› Attributes:Readonly

workingDirectory

This property holds an alternative working directory, i.e. the directory in which to execute commands via DockerContainer.run() or DockerContainer.execute(). See the official Docker documentation on WORKDIR for details.

This property was introduced in InCore 2.2.

› Type:String
› Signal:workingDirectoryChanged()
› Attributes:Writable

Methods

execute(String command, StringList arguments)

This method executes the given command in the container. The container has to be started before.

› Returns:Boolean

pull()

This method pulls the specified image from the corresponding Docker registry. This can be used for updating existing images.

This method was introduced in InCore 2.6.

› Returns:Boolean

run(String command, StringList arguments)

This method starts the container and runs the given command.

› Returns:Boolean

start()

This method starts the container if it is enabled and not running. It returns true if the container could be started successfully.

› Returns:Boolean

stop()

This method stops and removes the container if it is running. It returns true if the container has been stopped stopped and removed successfully.

› Returns:Boolean

Signals

errorOccurred()

This signal is emitted whenever an error has occurred, regardless of whether the error property has changed or not. In contrast to the change notification signal of the error property this signal is also emitted several times if a certain error occurs several times in succession.

mountsDataChanged(SignedInteger index)

This signal is emitted whenever the List.dataChanged() signal is emitted, i.e. the item at index in the mounts list itself emitted the dataChanged() signal.

networksDataChanged(SignedInteger index)

This signal is emitted whenever the List.dataChanged() signal is emitted, i.e. the item at index in the networks list itself emitted the dataChanged() signal.

volumesDataChanged(SignedInteger index)

This signal is emitted whenever the List.dataChanged() signal is emitted, i.e. the item at index in the volumes list itself emitted the dataChanged() signal.

Enumerations

Error

This enumeration describes all errors which can occur in DockerContainer objects. The most recently occurred error is stored in the error property.

Name Value Description
DockerContainer.NoError 0 No error occurred or was detected.
DockerContainer.ServiceNotFound 1 Service not found (parent is not a DockerService).
DockerContainer.ServiceNotRunning 2 DockerService not enabled or not running.
DockerContainer.ContainerNotRunning 3 Container is not running.
DockerContainer.ContainerStartFailed 4 Container could not be started e.g. due to invalid parameters or unavailable resources.
DockerContainer.ContainerAlreadyStarted 5 Container already started.
DockerContainer.MountWithoutStorage 6 Mount has no storage and no source path defined.
DockerContainer.MountSourcePathCreationFailed 7 Mount source path could not be created locally or on specified storage.
DockerContainer.InvalidMountSourcePath 8 Mount source path is not available and was not configured to be created automatically.
DockerContainer.InvalidVolumeConfiguration 9 Empty or invalid volume configuration (name or destination missing).
DockerContainer.InvalidNetworkConfiguration 10 Empty or invalid network configuration (name missing).
DockerContainer.InvalidName 11 Empty or invalid name.
DockerContainer.InvalidImage 12 Empty or invalid image.
DockerContainer.NetworkConnectionError 13 Failed to connect container to specified network(s).
DockerContainer.PullFailed 14 Failed to pull the specified image. Either the Docker registry is not reachable or the image does not exist.

NetworkMode

This enumeration describes the supported network modes for Docker containers. See the official Docker documentation on networking for details.

This enumeration was introduced in InCore 2.0.

Name Value Description
DockerContainer.Bridge 0 Use the bridge network driver for the container.
DockerContainer.Host 1 Use the host network driver for the container.
DockerContainer.Overlay 2 Use the overlay network driver for the container.
DockerContainer.MacVLAN 3 Use the macvlan network driver for the container.
DockerContainer.NoNetworking 4 Use the none network driver, i.e. disable networking for the container.

RestartPolicy

This enumeration describes the supported restart policies for Docker containers. See the official Docker documentation on restart policies for details.

Name Value Description
DockerContainer.NoRestart 0 Do not automatically restart the container when it exits.
DockerContainer.RestartOnFailure 1 Restart only if the container exits with a non-zero exit status.
DockerContainer.RestartUnlessStopped 2 Always restart the container regardless of the exit status, including on daemon startup, except if the container was put into a stopped state before the Docker daemon was stopped.
DockerContainer.RestartAlways 3 Always restart the container regardless of the exit status. With this policy the Docker daemon will try to restart the container indefinitely. The container will also always start on daemon startup, regardless of the current state of the container.

Example

import InCore.Foundation 2.5

Application {
    DockerService {
        DockerContainer {
            name: "nodered-example"
            image: "nodered/node-red:latest-minimal"
            ports: [ "1880:1880" ]
            environment: [ "FLOWS=myflows.json", "NODE_OPTIONS=--max_old_space_size=128" ]
            restartPolicy: DockerContainer.RestartAlways
        }
    }
}