Class DockerTemplateOptions
- java.lang.Object
-
- org.jclouds.compute.options.RunScriptOptions
-
- org.jclouds.compute.options.TemplateOptions
-
- org.jclouds.docker.compute.options.DockerTemplateOptions
-
- All Implemented Interfaces:
Cloneable
public class DockerTemplateOptions extends TemplateOptions implements Cloneable
Contains options supported by thecreateNodes
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 theconfigBuilder(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 providedConfig.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 Classes Modifier and Type Class Description static class
DockerTemplateOptions.Builder
-
Nested 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
Fields Modifier and Type Field Description protected Config.Builder
configBuilder
protected Integer
cpuShares
protected List<String>
dns
protected List<String>
env
protected Map<String,String>
extraHosts
protected String
hostname
protected Integer
memory
protected String
networkMode
protected boolean
openStdin
protected Map<Integer,Integer>
portBindings
protected boolean
privileged
protected Map<String,String>
volumes
protected List<String>
volumesFrom
-
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 Constructor Description DockerTemplateOptions()
-
Method Summary
-
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 Detail
-
privileged
protected boolean privileged
-
openStdin
protected boolean openStdin
-
configBuilder
protected Config.Builder configBuilder
-
-
Method Detail
-
clone
public DockerTemplateOptions clone()
- Overrides:
clone
in classTemplateOptions
-
copyTo
public void copyTo(TemplateOptions to)
- Overrides:
copyTo
in classTemplateOptions
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classTemplateOptions
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classTemplateOptions
-
toString
public String toString()
- Overrides:
toString
in classRunScriptOptions
-
volumes
public DockerTemplateOptions volumes(Map<String,String> volumes)
-
dns
public DockerTemplateOptions dns(Iterable<String> dns)
-
dns
public DockerTemplateOptions dns(String... dns)
-
hostname
public DockerTemplateOptions hostname(@Nullable String hostname)
-
memory
public DockerTemplateOptions memory(@Nullable Integer memory)
-
entrypoint
public DockerTemplateOptions entrypoint(Iterable<String> entrypoint)
-
entrypoint
public DockerTemplateOptions entrypoint(String... entrypoint)
-
commands
public DockerTemplateOptions commands(Iterable<String> commands)
-
commands
public DockerTemplateOptions commands(String... commands)
-
cpuShares
public DockerTemplateOptions cpuShares(@Nullable Integer cpuShares)
-
env
public DockerTemplateOptions env(Iterable<String> env)
-
env
public DockerTemplateOptions env(String... env)
-
portBindings
public DockerTemplateOptions portBindings(Map<Integer,Integer> 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
public DockerTemplateOptions networkMode(@Nullable String 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
public DockerTemplateOptions extraHosts(Map<String,String> 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
public DockerTemplateOptions volumesFrom(Iterable<String> volumesFrom)
Set list of containers to mount volumes from onto this container.- Parameters:
volumesFrom
- the list of container names
-
privileged
public DockerTemplateOptions privileged(boolean 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
public DockerTemplateOptions openStdin(boolean openStdin)
KeepSTDIN
open when running interactive workloads in the container.- Parameters:
openStdin
- Whether the container should keep STDIN open- Returns:
- this instance
-
configBuilder
public DockerTemplateOptions 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. 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!
-
getHostname
public String getHostname()
-
getMemory
public Integer getMemory()
-
getCpuShares
public Integer getCpuShares()
-
getNetworkMode
public String getNetworkMode()
-
getPrivileged
public boolean getPrivileged()
-
getOpenStdin
public boolean getOpenStdin()
-
getConfigBuilder
public Config.Builder getConfigBuilder()
-
blockOnPort
public DockerTemplateOptions blockOnPort(int port, int seconds)
When the node is started, wait until the following port is active- Overrides:
blockOnPort
in classTemplateOptions
-
inboundPorts
public DockerTemplateOptions inboundPorts(int... ports)
Opens the set of ports to public access.- Overrides:
inboundPorts
in classTemplateOptions
-
authorizePublicKey
public DockerTemplateOptions authorizePublicKey(String publicKey)
authorize an rsa ssh key.- Overrides:
authorizePublicKey
in classTemplateOptions
-
installPrivateKey
public DockerTemplateOptions installPrivateKey(String privateKey)
replaces the rsa ssh key used at login.- Overrides:
installPrivateKey
in classTemplateOptions
-
blockUntilRunning
public DockerTemplateOptions blockUntilRunning(boolean 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 inStatus#RUNNING
state
-
dontAuthorizePublicKey
public DockerTemplateOptions dontAuthorizePublicKey()
- Overrides:
dontAuthorizePublicKey
in classTemplateOptions
-
nameTask
public DockerTemplateOptions nameTask(String name)
- 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
public DockerTemplateOptions runAsRoot(boolean runAsRoot)
- Overrides:
runAsRoot
in classTemplateOptions
-
runScript
public DockerTemplateOptions runScript(Statement script)
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
public DockerTemplateOptions overrideLoginCredentials(LoginCredentials overridingCredentials)
- Overrides:
overrideLoginCredentials
in classTemplateOptions
-
overrideLoginPassword
public DockerTemplateOptions overrideLoginPassword(String password)
- Overrides:
overrideLoginPassword
in classTemplateOptions
-
overrideLoginPrivateKey
public DockerTemplateOptions overrideLoginPrivateKey(String privateKey)
- Overrides:
overrideLoginPrivateKey
in classTemplateOptions
-
overrideLoginUser
public DockerTemplateOptions overrideLoginUser(String loginUser)
- Overrides:
overrideLoginUser
in classTemplateOptions
-
overrideAuthenticateSudo
public DockerTemplateOptions overrideAuthenticateSudo(boolean authenticateSudo)
- Overrides:
overrideAuthenticateSudo
in classTemplateOptions
-
userMetadata
public DockerTemplateOptions userMetadata(Map<String,String> userMetadata)
- Overrides:
userMetadata
in classTemplateOptions
- Parameters:
userMetadata
- user-defined metadata to assign to this server
-
userMetadata
public DockerTemplateOptions userMetadata(String key, String value)
- Overrides:
userMetadata
in classTemplateOptions
- Parameters:
key
- key to place into the metadata mapvalue
- value to associate with that key
-
nodeNames
public DockerTemplateOptions nodeNames(Iterable<String> 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
public DockerTemplateOptions networks(Iterable<String> networks)
Assigns the created nodes to these networks- Overrides:
networks
in classTemplateOptions
-
-