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:
Overview
Properties
Methods
Signals
Enumerations
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
capAdd
This property holds security-related capabilities which to add to the container, e.g. NET_ADMIN.
This property was introduced in InCore 2.8.
- › Type:
StringList
- › Signal:
capAddChanged()
- › Attributes:
Writable
capDrop
This property holds security-related capabilities which to drop from the container, e.g. NET_ADMIN.
This property was introduced in InCore 2.8.
- › Type:
StringList
- › Signal:
capDropChanged()
- › 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:
- › 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
loggingDriver
This property holds which logging driver to use for forwarding/storing log messages from the container. See the DockerContainer.LoggingDriver enumeration for details.
This property was introduced in InCore 2.9.
- › Type:
- › Default:
- › Signal:
loggingDriverChanged()
- › 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:
- › 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:
- › Default:
- › 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:
- › 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:
- › Default:
- › 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:
- › 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 |
|---|---|---|
|
|
No error occurred or was detected. |
|
|
Service not found (parent is not a DockerService). |
|
|
DockerService not enabled or not running. |
|
|
Container is not running. |
|
|
Container could not be started e.g. due to invalid parameters or unavailable resources. |
|
|
Container already started. |
|
|
Mount has no storage and no source path defined. |
|
|
Mount source path could not be created locally or on specified storage. |
|
|
Mount source path is not available and was not configured to be created automatically. |
|
|
Empty or invalid volume configuration (name or destination missing). |
|
|
Empty or invalid network configuration (name missing). |
|
|
Empty or invalid name. |
|
|
Empty or invalid image. |
|
|
Failed to connect container to specified network(s). |
|
|
Failed to pull the specified image. Either the Docker registry is not reachable or the image does not exist. |
LoggingDriver
This enumeration describes the supported logging drivers for Docker containers. See the official Docker documentation on logging drivers policies for details.
This enumeration was introduced in InCore 2.9.
Name |
Value |
Description |
|---|---|---|
|
|
Do not process any log messages of the container. |
|
|
Write log messages to the local storage. |
|
|
Write log messages to the systemd journal. |
|
|
Write log messages to a container-specific JSON file. |
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 |
|---|---|---|
|
|
Use the bridge network driver for the container. |
|
|
Use the host network driver for the container. |
|
|
Use the overlay network driver for the container. |
|
|
Use the macvlan network driver for the container. |
|
|
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 |
|---|---|---|
|
|
Do not automatically restart the container when it exits. |
|
|
Restart only if the container exits with a non-zero exit status. |
|
|
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. |
|
|
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
}
}
}