Class DockerTemplateOptions
- All Implemented Interfaces:
Cloneable
createNodes
operation on the docker provider.
Usage
The recommended way to instantiate a DockerTemplateOptions object is to statically importDockerTemplateOptions.Builder.*
and invoke one of
the static creation methods, followed by an instance mutator if needed.
import static org.jclouds.docker.compute.options.DockerTemplateOptions.Builder.*;
ComputeService api = // get connection
templateBuilder.options(inboundPorts(22, 80, 8080, 443));
Set<? extends NodeMetadata> set = api.createNodesInGroup(tag, 2, templateBuilder.build());
Advanced Usage
In addition to basic configuration through its methods, this class also
provides possibility to work directly with Docker API configuration object (
Config.Builder
). When the
configBuilder(org.jclouds.docker.domain.Config.Builder)
is used to
configure not-null
configBuilder, then this configuration object
takes precedence over the other configuration in this class (i.e. the other
config entries are not used)
Note: The image
property in the provided Config.Builder
is rewritten by a placeholder value.
The real value is configured by ComputeServiceAdapter.
import static org.jclouds.docker.compute.options.DockerTemplateOptions.Builder.*;
ComputeService api = // get connection
DockerTemplateOptions options = DockerTemplateOptions.Builder
.configBuilder(
Config.builder().env(ImmutableList.<String> of("SSH_PORT=8822"))
.hostConfig(HostConfig.builder().networkMode("host").build()));
templateBuilder.options(options);
Set<? extends NodeMetadata> set = api.createNodesInGroup("sample-group", 1, templateBuilder.build());
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.jclouds.compute.options.TemplateOptions
TemplateOptions.ImmutableTemplateOptions
Nested classes/interfaces inherited from class org.jclouds.compute.options.RunScriptOptions
RunScriptOptions.ImmutableRunScriptOptions
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Config.Builder
protected Integer
protected String
protected Integer
protected String
protected boolean
protected boolean
Fields inherited from class org.jclouds.compute.options.TemplateOptions
blockUntilRunning, inboundPorts, networks, nodeNames, NONE, privateKey, publicKey, script, securityGroups, tags, userMetadata
Fields inherited from class org.jclouds.compute.options.RunScriptOptions
authenticateSudo, blockOnComplete, loginPassword, loginPrivateKey, loginUser, port, runAsRoot, seconds, taskName, wrapInInitScript
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionauthorizePublicKey
(String publicKey) authorize an rsa ssh key.blockOnPort
(int port, int seconds) When the node is started, wait until the following port is activeblockUntilRunning
(boolean blockUntilRunning) Noteclone()
configBuilder
(Config.Builder configBuilder) This method sets Config.Builder configuration object, which can be used as a replacement for all the other settings from this class.void
entrypoint
(Iterable<String> entrypoint) entrypoint
(String... entrypoint) boolean
extraHosts
(Map<String, String> extraHosts) Set extra hosts file entries for a container.getDns()
getEnv()
boolean
boolean
int
hashCode()
inboundPorts
(int... ports) Opens the set of ports to public access.installPrivateKey
(String privateKey) replaces the rsa ssh key used at login.networkMode
(String networkMode) Sets the networking mode for the container.Assigns the created nodes to these networksspecifies names to be used for the created nodes.openStdin
(boolean openStdin) KeepSTDIN
open when running interactive workloads in the container.overrideAuthenticateSudo
(boolean authenticateSudo) overrideLoginCredentials
(LoginCredentials overridingCredentials) overrideLoginPassword
(String password) overrideLoginPrivateKey
(String privateKey) overrideLoginUser
(String loginUser) portBindings
(Map<Integer, Integer> portBindings) Set port bindings between the Docker host and a container.privileged
(boolean privileged) By default, Docker containers are unprivileged and cannot execute privileged operations or access certain host devices.runAsRoot
(boolean runAsRoot) This script will be executed as the root user upon system startup.toString()
userMetadata
(String key, String value) userMetadata
(Map<String, String> userMetadata) volumesFrom
(Iterable<String> volumesFrom) Set list of containers to mount volumes from onto this container.Methods inherited from class org.jclouds.compute.options.TemplateOptions
as, blockOnComplete, getGroups, getInboundPorts, getNetworks, getNodeNames, getPrivateKey, getPublicKey, getRunScript, getTags, getUserMetadata, networks, runScript, securityGroups, securityGroups, shouldBlockUntilRunning, string, tags, wrapInInitScript
Methods inherited from class org.jclouds.compute.options.RunScriptOptions
copyTo, getLoginPassword, getLoginPrivateKey, getLoginUser, getPort, getSeconds, getTaskName, hasLoginPassword, hasLoginPasswordOption, hasLoginPrivateKey, hasLoginPrivateKeyOption, overrideLoginPassword, overrideLoginPrivateKey, shouldAuthenticateSudo, shouldBlockOnComplete, shouldRunAsRoot, shouldWrapInInitScript
-
Field Details
-
dns
-
hostname
-
memory
-
volumes
-
env
-
portBindings
-
networkMode
-
extraHosts
-
volumesFrom
-
privileged
protected boolean privileged -
openStdin
protected boolean openStdin -
configBuilder
-
-
Constructor Details
-
DockerTemplateOptions
public DockerTemplateOptions()
-
-
Method Details
-
clone
- Overrides:
clone
in classTemplateOptions
-
copyTo
- Overrides:
copyTo
in classTemplateOptions
-
equals
- Overrides:
equals
in classTemplateOptions
-
hashCode
public int hashCode()- Overrides:
hashCode
in classTemplateOptions
-
toString
- Overrides:
toString
in classRunScriptOptions
-
volumes
-
dns
-
dns
-
hostname
-
memory
-
entrypoint
-
entrypoint
-
commands
-
commands
-
env
-
env
-
portBindings
Set port bindings between the Docker host and a container.The
Map
keys are host ports number, and the value for an entry is the container port number. This is the same order as the arguments for the--publish
command-line option todocker run
which ishostPort:containerPort
.- Parameters:
portBindings
- the map of host to container port bindings
-
networkMode
Sets the networking mode for the container.Supported values are:
bridge
,none
,host
,networkname
,networkid
orcontainer:[name|id]
- Parameters:
networkMode
-- Returns:
- this instance
-
extraHosts
Set extra hosts file entries for a container.The
Map
keys are host names, and the value is an IP address that can be accessed by the container. This is the same order as the arguments for the--add-host
command-line option todocker run
.- Parameters:
extraHosts
- the map of host names to IP addresses
-
volumesFrom
Set list of containers to mount volumes from onto this container.- Parameters:
volumesFrom
- the list of container names
-
privileged
By default, Docker containers are unprivileged and cannot execute privileged operations or access certain host devices.- Parameters:
privileged
- Whether the container should run in privileged mode or not- Returns:
- this instance
-
openStdin
KeepSTDIN
open when running interactive workloads in the container.- Parameters:
openStdin
- Whether the container should keep STDIN open- Returns:
- this instance
-
configBuilder
This method sets Config.Builder configuration object, which can be used as a replacement for all the other settings from this class. Some values in the provided Config.Builder instance (the image name for instance) can be ignored or their value can be changed.- Parameters:
configBuilder
- Config.Builder instance. This instance can be changed in this method!
-
getVolumes
-
getDns
-
getVolumesFrom
-
getHostname
-
getMemory
-
getEntrypoint
-
getCommands
-
getEnv
-
getPortBindings
-
getNetworkMode
-
getExtraHosts
-
getPrivileged
public boolean getPrivileged() -
getOpenStdin
public boolean getOpenStdin() -
getConfigBuilder
-
blockOnPort
When the node is started, wait until the following port is active- Overrides:
blockOnPort
in classTemplateOptions
-
inboundPorts
Opens the set of ports to public access.- Overrides:
inboundPorts
in classTemplateOptions
-
authorizePublicKey
authorize an rsa ssh key.- Overrides:
authorizePublicKey
in classTemplateOptions
-
installPrivateKey
replaces the rsa ssh key used at login.- Overrides:
installPrivateKey
in classTemplateOptions
-
blockUntilRunning
Note
As of version 1.1.0, this option is incompatible withTemplateOptions.runScript(Statement)
andRunScriptOptions.blockOnComplete(boolean)
, as all current implementations utilize ssh in order to execute scripts.- Overrides:
blockUntilRunning
in classTemplateOptions
- Parameters:
blockUntilRunning
- (default true) whether to block until the nodes in this template are ininvalid reference
Status#RUNNING
-
dontAuthorizePublicKey
- Overrides:
dontAuthorizePublicKey
in classTemplateOptions
-
nameTask
- Overrides:
nameTask
in classTemplateOptions
- Returns:
- What to call the task relating to this script; default
jclouds-script-timestamp
where timestamp is millis since epoch
-
runAsRoot
- Overrides:
runAsRoot
in classTemplateOptions
-
runScript
This script will be executed as the root user upon system startup. This script gets a prologue, so no #!/bin/bash required, path set up, etc- Overrides:
runScript
in classTemplateOptions
-
overrideLoginCredentials
- Overrides:
overrideLoginCredentials
in classTemplateOptions
-
overrideLoginPassword
- Overrides:
overrideLoginPassword
in classTemplateOptions
-
overrideLoginPrivateKey
- Overrides:
overrideLoginPrivateKey
in classTemplateOptions
-
overrideLoginUser
- Overrides:
overrideLoginUser
in classTemplateOptions
-
overrideAuthenticateSudo
- Overrides:
overrideAuthenticateSudo
in classTemplateOptions
-
userMetadata
- Overrides:
userMetadata
in classTemplateOptions
- Parameters:
userMetadata
- user-defined metadata to assign to this server
-
userMetadata
- Overrides:
userMetadata
in classTemplateOptions
- Parameters:
key
- key to place into the metadata mapvalue
- value to associate with that key
-
nodeNames
specifies names to be used for the created nodes. Note that this does not guarantee uniqueness - if there are already existing nodes with a name specified here, there will still be a new node created with the same name. Also, if more nodes are to be created than there are names, subsequent names will use the default naming strategy for that cloud.- Overrides:
nodeNames
in classTemplateOptions
-
networks
Assigns the created nodes to these networks- Overrides:
networks
in classTemplateOptions
-