- java.lang.Object
-
- com.oracle.bedrock.runtime.docker.Docker
-
- All Implemented Interfaces:
com.oracle.bedrock.Option
public class Docker extends Object implements com.oracle.bedrock.Option
An encapsulation of the various settings required to run Docker commands.A
Dockerinstance is immutable, methods that add options and configuration to thisDockerenvironment return a new instance of aDockerenvironment with the modifications appliedCopyright (c) 2016. All Rights Reserved. Oracle Corporation.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.- Author:
- Jonathan Knight
-
-
Field Summary
Fields Modifier and Type Field Description static StringARG_CONFIGLocation of client config files E.G.static StringARG_DEBUGEnable debug mode E.G.static StringARG_HELPPrint usage E.G.static StringARG_HOSTDaemon socket(s) to connect tostatic StringARG_LOG_LEVELSet the logging level E.G.static StringARG_TLSUse TLS; implied by --tlsverify E.G.static StringARG_TLS_CA_CERTTrust certs signed only by this CA E.G.static StringARG_TLS_CERTPath to TLS certificate file E.G.static StringARG_TLS_KEYPath to TLS key file E.G.static StringARG_TLS_VERIFYUse TLS and verify the remote E.G.static StringARG_VERSIONPrint version information and quit E.G.static StringDEFAULT_EXECUTABLEThe default name of the executable to use to execute Docker commands.static StringENV_DOCKER_API_VERSIONThe API version to use (e.g.static StringENV_DOCKER_CERT_PATHThe location of your authentication keys.static StringENV_DOCKER_CONFIGThe location of your client configuration files.static StringENV_DOCKER_CONTENT_TRUSTWhen set Docker uses notary to sign and verify images.static StringENV_DOCKER_CONTENT_TRUST_SERVERThe URL of the Notary server to use.static StringENV_DOCKER_DRIVERThe graph driver to use.static StringENV_DOCKER_HOSTDaemon socket to connect to.static StringENV_DOCKER_NOWARN_KERNEL_VERSIONPrevent warnings that your Linux kernel is unsuitable for Docker.static StringENV_DOCKER_RAMDISKIf set this will disable ‘pivot_root’.static StringENV_DOCKER_TLS_VERIFYWhen set Docker uses TLS and verifies the remote.static StringENV_DOCKER_TMPDIRLocation for temporary Docker files.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DockerapiVersion(String version)Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_API_VERSIONenvironment variable.static Dockerauto()Configure Docker from the current environment.DockerconfigAt(Object config)Obtain a copy of thisDockerenvironment with the addition of the specified location of client config files.DockercontentTrustAt(String url)Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_CONTENT_TRUST_SERVERenvironment variable.DockercontentTrustEnabled(boolean enabled)Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_CONTENT_TRUSTenvironment variable.static DockerdaemonAt(String address)Manually configure Docker.Dockerdebug(boolean enabled)Obtain a copy of thisDockerenvironment with the addition of the specified debug setting.DockerdockerExecutableOf(String executable)Set the executable name to use to run Docker client commands.Dockerdriver(String driver)Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_DRIVERenvironment variable.List<com.oracle.bedrock.runtime.options.Argument>getArguments()Obtain an immutable copy of the command lineArguments for thisDockerenvironment.StringgetBaseImage(Class<? extends com.oracle.bedrock.runtime.Application> applicationClass)Obtain the default base image name to use for applications of a givenClass.StringgetDaemonAddress()Obtain the Docker address that thisDockerenvironment will use to communicate with the Docker daemon.InetAddressgetDaemonInetAddress(com.oracle.bedrock.runtime.Platform clientPlatform)StringgetDefaultNetworkName()Obtain the name of the default network to connect automatically run containers to.StringgetDockerExecutable()Obtain the executable name to use to run Docker client commands.List<com.oracle.bedrock.runtime.options.EnvironmentVariable>getEnvironmentVariables()Obtain an immutable copy of theEnvironmentVariables for thisDockerenvironment.InetAddressgetValidLocalAddress()Try to find a valid localInetAddressthat is routable to the Docker daemon.DockerlogLevel(String level)Obtain a copy of thisDockerenvironment with the addition of the specified log level.static Dockermachine(String machineName)Configure Docker using the specified Docker Machine machine name.static Dockermachine(String machineName, DockerMachine machine, com.oracle.bedrock.Option... options)Configure Docker using the specified Docker Machine machine name.DockernoWarnKernelVersion(boolean noWarn)Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_NOWARN_KERNEL_VERSIONenvironment variable.DockerramDisk(boolean use)Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_RAMDISKenvironment variable.DockertempFilesAt(File temp)Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_TMPDIRenvironment variable.Dockertls(boolean enabled)Obtain a copy of thisDockerenvironment with the addition of the specified tls setting.DockertlsCACert(File location)Obtain a copy of thisDockerenvironment with the addition of the specified Trust certs signed only by this CA.DockertlsCert(File location)Obtain a copy of thisDockerenvironment with the addition of the specified path to TLS certificate file.DockertlsKey(File location)Obtain a copy of thisDockerenvironment with the addition of the specified path to TLS key file.DockertlsVerify(boolean verify)Obtain a copy of thisDockerenvironment with the addition of the specified TLS verification setting.DockerwithBaseImage(Class<? extends com.oracle.bedrock.runtime.Application> applicationClass, String baseImageName)Add a default base image to use for a specific type of application class.DockerwithCommandOptions(com.oracle.bedrock.runtime.options.Argument... opts)Obtain a copy of thisDockerenvironment with the addition of the specified command line options.DockerwithDaemonAddress(String address)DockerwithDefaultNetwork(String networkName)Obtain a newDockerenvironment that is a copy of this environment with the addition of the specified default network name.DockerwithEnvironmentVariables(com.oracle.bedrock.runtime.options.EnvironmentVariable... environmentVariables)Obtain a copy of thisDockerenvironment with the addition of the specifiedEnvironmentVariables.DockerwithEnvironmentVariables(List<com.oracle.bedrock.runtime.options.EnvironmentVariable> environmentVariables)Obtain a copy of thisDockerenvironment with the addition of the specifiedEnvironmentVariables.
-
-
-
Field Detail
-
ENV_DOCKER_API_VERSION
public static final String ENV_DOCKER_API_VERSION
The API version to use (e.g. 1.19)- See Also:
- Constant Field Values
-
ENV_DOCKER_CONFIG
public static final String ENV_DOCKER_CONFIG
The location of your client configuration files.- See Also:
- Constant Field Values
-
ENV_DOCKER_CERT_PATH
public static final String ENV_DOCKER_CERT_PATH
The location of your authentication keys.- See Also:
- Constant Field Values
-
ENV_DOCKER_DRIVER
public static final String ENV_DOCKER_DRIVER
The graph driver to use.- See Also:
- Constant Field Values
-
ENV_DOCKER_HOST
public static final String ENV_DOCKER_HOST
Daemon socket to connect to.- See Also:
- Constant Field Values
-
ENV_DOCKER_NOWARN_KERNEL_VERSION
public static final String ENV_DOCKER_NOWARN_KERNEL_VERSION
Prevent warnings that your Linux kernel is unsuitable for Docker.- See Also:
- Constant Field Values
-
ENV_DOCKER_RAMDISK
public static final String ENV_DOCKER_RAMDISK
If set this will disable ‘pivot_root’.- See Also:
- Constant Field Values
-
ENV_DOCKER_TLS_VERIFY
public static final String ENV_DOCKER_TLS_VERIFY
When set Docker uses TLS and verifies the remote.- See Also:
- Constant Field Values
-
ENV_DOCKER_CONTENT_TRUST
public static final String ENV_DOCKER_CONTENT_TRUST
When set Docker uses notary to sign and verify images. Equates to --disable-content-trust=false for build, create, pull, push, run.- See Also:
- Constant Field Values
-
ENV_DOCKER_CONTENT_TRUST_SERVER
public static final String ENV_DOCKER_CONTENT_TRUST_SERVER
The URL of the Notary server to use. This defaults to the same URL as the registry.- See Also:
- Constant Field Values
-
ENV_DOCKER_TMPDIR
public static final String ENV_DOCKER_TMPDIR
Location for temporary Docker files.- See Also:
- Constant Field Values
-
ARG_CONFIG
public static final String ARG_CONFIG
Location of client config files E.G. --config=~/.docker- See Also:
- Constant Field Values
-
ARG_DEBUG
public static final String ARG_DEBUG
Enable debug mode E.G. --debug=false- See Also:
- Constant Field Values
-
ARG_HOST
public static final String ARG_HOST
Daemon socket(s) to connect to- See Also:
- Constant Field Values
-
ARG_HELP
public static final String ARG_HELP
Print usage E.G. --help=false- See Also:
- Constant Field Values
-
ARG_LOG_LEVEL
public static final String ARG_LOG_LEVEL
Set the logging level E.G. --log-level=info- See Also:
- Constant Field Values
-
ARG_TLS
public static final String ARG_TLS
Use TLS; implied by --tlsverify E.G. --tls=false- See Also:
- Constant Field Values
-
ARG_TLS_CA_CERT
public static final String ARG_TLS_CA_CERT
Trust certs signed only by this CA E.G. --tlscacert=~/.docker/ca.pem- See Also:
- Constant Field Values
-
ARG_TLS_CERT
public static final String ARG_TLS_CERT
Path to TLS certificate file E.G. --tlscert=~/.docker/cert.pem- See Also:
- Constant Field Values
-
ARG_TLS_KEY
public static final String ARG_TLS_KEY
Path to TLS key file E.G. --tlskey=~/.docker/key.pem- See Also:
- Constant Field Values
-
ARG_TLS_VERIFY
public static final String ARG_TLS_VERIFY
Use TLS and verify the remote E.G. --tlsverify=false- See Also:
- Constant Field Values
-
ARG_VERSION
public static final String ARG_VERSION
Print version information and quit E.G. --version=false- See Also:
- Constant Field Values
-
DEFAULT_EXECUTABLE
public static final String DEFAULT_EXECUTABLE
The default name of the executable to use to execute Docker commands.- See Also:
- Constant Field Values
-
-
Method Detail
-
getDaemonAddress
public String getDaemonAddress()
Obtain the Docker address that thisDockerenvironment will use to communicate with the Docker daemon.- Returns:
- the Docker address that this
Dockerenvironment will use to communicate with the Docker daemon
-
dockerExecutableOf
public Docker dockerExecutableOf(String executable)
Set the executable name to use to run Docker client commands.This would typically be "docker" but some third-party add-ons provide other clients.
- Parameters:
executable- the name of the executable or null to use the default of "docker"- Returns:
- a new instance of
Dockerthat is a copy of this instance with the addition of the executable name change
-
getDockerExecutable
public String getDockerExecutable()
Obtain the executable name to use to run Docker client commands.- Returns:
- the executable name to use to run Docker client commands
-
getArguments
public List<com.oracle.bedrock.runtime.options.Argument> getArguments()
Obtain an immutable copy of the command lineArguments for thisDockerenvironment.- Returns:
- an immutable copy of the command line
Arguments for thisDockerenvironment
-
getEnvironmentVariables
public List<com.oracle.bedrock.runtime.options.EnvironmentVariable> getEnvironmentVariables()
Obtain an immutable copy of theEnvironmentVariables for thisDockerenvironment.- Returns:
- an immutable copy of the
EnvironmentVariables for thisDockerenvironment
-
withBaseImage
public Docker withBaseImage(Class<? extends com.oracle.bedrock.runtime.Application> applicationClass, String baseImageName)
Add a default base image to use for a specific type of application class.- Parameters:
applicationClass- theClassof the applicationbaseImageName- the base image name to use- Returns:
- a new instance of
Dockerthat is a copy of this instance with the addition of the base image default - Throws:
IllegalArgumentException- if the application class is null or if the base image name is null or blank- See Also:
getBaseImage(Class)
-
getBaseImage
public String getBaseImage(Class<? extends com.oracle.bedrock.runtime.Application> applicationClass)
Obtain the default base image name to use for applications of a givenClass.- Parameters:
applicationClass- the applicationClass- Returns:
- the name of the base image to use
- See Also:
withBaseImage(Class, String)
-
withDefaultNetwork
public Docker withDefaultNetwork(String networkName)
Obtain a newDockerenvironment that is a copy of this environment with the addition of the specified default network name.- Parameters:
networkName- the name of the default network to connect automatically created containers to- Returns:
- a new
Dockerenvironment that is a copy of this environment with the addition of the specified default network name
-
getDefaultNetworkName
public String getDefaultNetworkName()
Obtain the name of the default network to connect automatically run containers to.- Returns:
- the name of the default network to connect automatically run containers to
-
configAt
public Docker configAt(Object config)
Obtain a copy of thisDockerenvironment with the addition of the specified location of client config files.Equates to the Docker
--configcommand option.- Parameters:
config- the config- Returns:
- a copy of this
Dockerenvironment with the addition of the specified location of client config files
-
debug
public Docker debug(boolean enabled)
Obtain a copy of thisDockerenvironment with the addition of the specified debug setting.Equates to the Docker
--debugcommand option.- Parameters:
enabled- true to enable debug, false to disable debug- Returns:
- a copy of this
Dockerenvironment with the addition of the specified debug setting
-
logLevel
public Docker logLevel(String level)
Obtain a copy of thisDockerenvironment with the addition of the specified log level.Equates to the Docker
--log-levelcommand option.- Parameters:
level- the logging level to use, for example "info"- Returns:
- a copy of this
Dockerenvironment with the addition of the specified log level
-
tls
public Docker tls(boolean enabled)
Obtain a copy of thisDockerenvironment with the addition of the specified tls setting.Equates to the Docker
--tlscommand option.- Parameters:
enabled- true to enables TLS, false to disable TLS- Returns:
- a copy of this
Dockerenvironment with the addition of the specified tls setting
-
tlsCACert
public Docker tlsCACert(File location)
Obtain a copy of thisDockerenvironment with the addition of the specified Trust certs signed only by this CA.Equates to the Docker
--tlscacertcommand option.- Parameters:
location- the location of the certificates- Returns:
- a copy of this
Dockerenvironment with the addition of the specified Trust certs signed only by this CA
-
tlsCert
public Docker tlsCert(File location)
Obtain a copy of thisDockerenvironment with the addition of the specified path to TLS certificate file.Equates to the Docker
--tlscertcommand option.- Parameters:
location- the location of the certificate file- Returns:
- a copy of this
Dockerenvironment with the addition of the specified path to TLS certificate file
-
tlsKey
public Docker tlsKey(File location)
Obtain a copy of thisDockerenvironment with the addition of the specified path to TLS key file.Equates to the Docker
--tlskeycommand option.- Parameters:
location- the location of the key file- Returns:
- a copy of this
Dockerenvironment with the addition of the specified path to TLS key file
-
tlsVerify
public Docker tlsVerify(boolean verify)
Obtain a copy of thisDockerenvironment with the addition of the specified TLS verification setting.Equates to the Docker
--tlsverifycommand option.- Parameters:
verify- true to enable TLS verification, false to disable TLS verification- Returns:
- a copy of this
Dockerenvironment with the addition of the specified TLS verification setting
-
apiVersion
public Docker apiVersion(String version)
Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_API_VERSIONenvironment variable.- Parameters:
version- The API version to use (e.g. 1.19)- Returns:
- a copy of this
Dockerenvironment with the addition of the specifiedDOCKER_API_VERSIONenvironment variable
-
driver
public Docker driver(String driver)
Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_DRIVERenvironment variable.- Parameters:
driver- The graph driver to use- Returns:
- a copy of this
Dockerenvironment with the addition of the specifiedDOCKER_DRIVERenvironment variable
-
noWarnKernelVersion
public Docker noWarnKernelVersion(boolean noWarn)
Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_NOWARN_KERNEL_VERSIONenvironment variable.- Parameters:
noWarn- true to prevent warnings that your Linux kernel is unsuitable for Docker- Returns:
- a copy of this
Dockerenvironment with the addition of the specifiedDOCKER_NOWARN_KERNEL_VERSIONenvironment variable
-
ramDisk
public Docker ramDisk(boolean use)
Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_RAMDISKenvironment variable.- Parameters:
use- true to disable ‘pivot_root’- Returns:
- a copy of this
Dockerenvironment with the addition of the specifiedDOCKER_RAMDISKenvironment variable
-
contentTrustEnabled
public Docker contentTrustEnabled(boolean enabled)
Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_CONTENT_TRUSTenvironment variable.Equates to --disable-content-trust=false for build, create, pull, push, run
- Parameters:
enabled- true to set Docker to use notary to sign and verify images- Returns:
- a copy of this
Dockerenvironment with the addition of the specifiedDOCKER_CONTENT_TRUSTenvironment variable
-
contentTrustAt
public Docker contentTrustAt(String url)
Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_CONTENT_TRUST_SERVERenvironment variable.This defaults to the same URL as the registry.
- Parameters:
url- the URL of the Notary server to use.- Returns:
- a copy of this
Dockerenvironment with the addition of the specifiedDOCKER_CONTENT_TRUST_SERVERenvironment variable
-
tempFilesAt
public Docker tempFilesAt(File temp)
Obtain a copy of thisDockerenvironment with the addition of the specifiedDOCKER_TMPDIRenvironment variable.- Parameters:
temp- the location for temporary Docker files- Returns:
- a copy of this
Dockerenvironment with the addition of the specifiedDOCKER_TMPDIRenvironment variable
-
withCommandOptions
public Docker withCommandOptions(com.oracle.bedrock.runtime.options.Argument... opts)
Obtain a copy of thisDockerenvironment with the addition of the specified command line options.Docker command line options are placed on the command line before the name of the command to be executed. For example if the command being executed is the
buildcommand the command line would be:docker command-options build command-args- Parameters:
opts- the command line options- Returns:
- a copy of this
Dockerenvironment with the addition of the specified command line options
-
withEnvironmentVariables
public Docker withEnvironmentVariables(com.oracle.bedrock.runtime.options.EnvironmentVariable... environmentVariables)
Obtain a copy of thisDockerenvironment with the addition of the specifiedEnvironmentVariables.The
EnvironmentVariables will be applied to any process running Docker commands using thisDockerenvironment.- Parameters:
environmentVariables- theEnvironmentVariables to use- Returns:
- a copy of this
Dockerenvironment with the addition of the specifiedEnvironmentVariables
-
withEnvironmentVariables
public Docker withEnvironmentVariables(List<com.oracle.bedrock.runtime.options.EnvironmentVariable> environmentVariables)
Obtain a copy of thisDockerenvironment with the addition of the specifiedEnvironmentVariables.The
EnvironmentVariables will be applied to any process running Docker commands using thisDockerenvironment.- Parameters:
environmentVariables- theEnvironmentVariables to use- Returns:
- a copy of this
Dockerenvironment with the addition of the specifiedEnvironmentVariables
-
getValidLocalAddress
public InetAddress getValidLocalAddress()
Try to find a valid localInetAddressthat is routable to the Docker daemon.If the daemon address does not have the tcp:// prefix then it is probably local, i.e. unix:// or fd:// so the address returned will be the address of the
LocalPlatform.For a tcp:// address the host and port are parsed out and a socket opened to the address. The local address of the socket is returned.
If any errors occur the address of the
LocalPlatformis returned.- Returns:
- an
InetAddressthat should be visible from the daemon
-
getDaemonInetAddress
public InetAddress getDaemonInetAddress(com.oracle.bedrock.runtime.Platform clientPlatform)
-
auto
@Default public static Docker auto()
Configure Docker from the current environment.Using auto configuration assumes that Docker is already configured on the client platform with environment variables pointing to the Docker daemon or the Docker daemon is local to the client platform.
- Returns:
- a new
Docker
-
machine
public static Docker machine(String machineName)
Configure Docker using the specified Docker Machine machine name.Docker client commands will be executed with the correct settings to connect to the Docker daemon on the specified Docker Machine instance.
- Parameters:
machineName- the name of a Docker Machine machine- Returns:
- a new
Docker
-
machine
public static Docker machine(String machineName, DockerMachine machine, com.oracle.bedrock.Option... options)
Configure Docker using the specified Docker Machine machine name.Docker client commands will be executed with the correct settings to connect to the Docker daemon on the specified Docker Machine instance.
- Parameters:
machineName- the name of a Docker Machine machinemachine- theDockerMachineenvironmentoptions- theOptions- Returns:
- a new
Docker
-
-