public class DefaultDockerClient extends Object implements DockerClient, Closeable
Modifier and Type | Class and Description |
---|---|
static class |
DefaultDockerClient.Builder |
DockerClient.AttachParameter, DockerClient.BuildParameter, DockerClient.ExecParameter, DockerClient.ExecStartParameter, DockerClient.ListContainersParam, DockerClient.ListImagesFilterParam, DockerClient.ListImagesParam, DockerClient.LogsParameter
Modifier and Type | Field and Description |
---|---|
private AuthConfig |
authConfig |
private javax.ws.rs.client.Client |
client |
private static javax.ws.rs.core.GenericType<List<Container>> |
CONTAINER_LIST |
private static Pattern |
CONTAINER_NAME_PATTERN |
private static org.glassfish.jersey.client.ClientConfig |
DEFAULT_CONFIG |
private static long |
DEFAULT_CONNECT_TIMEOUT_MILLIS |
private static int |
DEFAULT_CONNECTION_POOL_SIZE |
static String |
DEFAULT_HOST |
static int |
DEFAULT_PORT |
private static long |
DEFAULT_READ_TIMEOUT_MILLIS |
static String |
DEFAULT_UNIX_ENDPOINT |
private static javax.ws.rs.core.GenericType<List<Image>> |
IMAGE_LIST |
private static org.slf4j.Logger |
log |
static long |
NO_TIMEOUT |
private javax.ws.rs.client.Client |
noTimeoutClient |
private static javax.ws.rs.core.GenericType<List<RemovedImage>> |
REMOVED_IMAGE_LIST |
private static String |
UNIX_SCHEME |
private URI |
uri |
private static String |
VERSION |
Modifier | Constructor and Description |
---|---|
protected |
DefaultDockerClient(DefaultDockerClient.Builder builder)
Create a new client using the configuration of the builder.
|
|
DefaultDockerClient(String uri)
Create a new client with default configuration.
|
|
DefaultDockerClient(URI uri)
Create a new client with default configuration.
|
|
DefaultDockerClient(URI uri,
DockerCertificates dockerCertificates)
Create a new client with default configuration.
|
Modifier and Type | Method and Description |
---|---|
LogStream |
attachContainer(String containerId,
DockerClient.AttachParameter... params)
Attach to the container id
|
int |
auth(AuthConfig authConfig)
Check auth configuration.
|
private String |
authHeader() |
private String |
authHeader(AuthConfig authConfig) |
String |
build(Path directory,
DockerClient.BuildParameter... params)
Build a docker image.
|
String |
build(Path directory,
ProgressHandler handler,
DockerClient.BuildParameter... params)
Build a docker image.
|
String |
build(Path directory,
String name,
DockerClient.BuildParameter... params)
Build a docker image.
|
String |
build(Path directory,
String name,
ProgressHandler handler,
DockerClient.BuildParameter... params)
Build a docker image.
|
static DefaultDockerClient.Builder |
builder()
Create a new
DefaultDockerClient builder. |
void |
close()
Closes any and all underlying connections to docker, and release resources.
|
ContainerCreation |
commitContainer(String containerId,
String repo,
String tag,
ContainerConfig config,
String comment,
String author)
Create a new image from a container's changes.
|
InputStream |
copyContainer(String containerId,
String path)
Copies some files out of a container.
|
ContainerCreation |
createContainer(ContainerConfig config)
Create a docker container.
|
ContainerCreation |
createContainer(ContainerConfig config,
String name)
Create a docker container.
|
private static String |
defaultEndpoint() |
String |
execCreate(String containerId,
String[] cmd,
DockerClient.ExecParameter... params)
Sets up an exec instance in a running container id.
|
LogStream |
execStart(String execId,
DockerClient.ExecStartParameter... params)
Starts a previously set up exec instance id.
|
InputStream |
exportContainer(String containerId)
Export a docker container as a tar archive.
|
static DefaultDockerClient.Builder |
fromEnv()
Create a new
DefaultDockerClient builder prepopulated with values loaded
from the DOCKER_HOST and DOCKER_CERT_PATH environment variables. |
(package private) javax.ws.rs.client.Client |
getClient() |
private org.apache.http.impl.conn.PoolingHttpClientConnectionManager |
getConnectionManager(DefaultDockerClient.Builder builder) |
(package private) javax.ws.rs.client.Client |
getNoTimeoutClient() |
private org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> |
getSchemeRegistry(DefaultDockerClient.Builder builder) |
Info |
info()
Get docker instance information.
|
ContainerInfo |
inspectContainer(String containerId)
Inspect a docker container.
|
ImageInfo |
inspectImage(String image)
Inspect a docker container image.
|
void |
killContainer(String containerId)
Kill a docker container.
|
List<Container> |
listContainers(DockerClient.ListContainersParam... params)
List docker containers.
|
List<Image> |
listImages(DockerClient.ListImagesParam... params) |
LogStream |
logs(String containerId,
DockerClient.LogsParameter... params)
Get docker container logs.
|
private String |
message(javax.ws.rs.core.Response response) |
private javax.ws.rs.client.WebTarget |
noTimeoutResource() |
void |
pauseContainer(String containerId)
Pause a docker container.
|
String |
ping()
Ping the docker daemon.
|
private RuntimeException |
propagate(String method,
javax.ws.rs.client.WebTarget resource,
Exception e) |
void |
pull(String image)
Pull a docker container image.
|
void |
pull(String image,
AuthConfig authConfig)
Pull a private docker container image.
|
void |
pull(String image,
AuthConfig authConfig,
ProgressHandler handler)
Pull a private docker container image, using a custom ProgressMessageHandler.
|
void |
pull(String image,
ProgressHandler handler)
Pull a docker container image, using a custom ProgressMessageHandler
|
void |
push(String image)
Push a docker container image.
|
void |
push(String image,
ProgressHandler handler)
Push a docker container image, using a custom ProgressHandler
|
void |
removeContainer(String containerId)
Remove a docker container.
|
void |
removeContainer(String containerId,
boolean removeVolumes)
Remove a docker container.
|
List<RemovedImage> |
removeImage(String image)
Remove a docker image.
|
List<RemovedImage> |
removeImage(String image,
boolean force,
boolean noPrune)
Remove a docker image.
|
private <T> T |
request(String method,
Class<T> clazz,
javax.ws.rs.client.WebTarget resource,
javax.ws.rs.client.Invocation.Builder request) |
private <T> T |
request(String method,
Class<T> clazz,
javax.ws.rs.client.WebTarget resource,
javax.ws.rs.client.Invocation.Builder request,
javax.ws.rs.client.Entity<?> entity) |
private <T> T |
request(String method,
javax.ws.rs.core.GenericType<T> type,
javax.ws.rs.client.WebTarget resource,
javax.ws.rs.client.Invocation.Builder request) |
private void |
request(String method,
javax.ws.rs.client.WebTarget resource,
javax.ws.rs.client.Invocation.Builder request) |
private void |
request(String method,
javax.ws.rs.client.WebTarget resource,
javax.ws.rs.client.Invocation.Builder request,
javax.ws.rs.client.Entity<?> entity) |
private javax.ws.rs.client.WebTarget |
resource() |
void |
restartContainer(String containerId)
Restart a docker container.
|
void |
restartContainer(String containerId,
int secondsToWaitBeforeRestart)
Restart a docker container.
|
void |
startContainer(String containerId)
Start a docker container.
|
void |
startContainer(String containerId,
HostConfig hostConfig)
Start a docker container.
|
void |
stopContainer(String containerId,
int secondsToWaitBeforeKilling)
Stop a docker container by sending a SIGTERM, and following up with a SIGKILL if the
container doesn't exit gracefully and in a timely manner.
|
void |
tag(String image,
String name)
Tag a docker image.
|
void |
unpauseContainer(String containerId)
Unpause a docker container.
|
Version |
version()
Get the docker version.
|
ContainerExit |
waitContainer(String containerId)
Wait for a docker container to exit.
|
public static final String DEFAULT_UNIX_ENDPOINT
public static final String DEFAULT_HOST
public static final int DEFAULT_PORT
private static final String UNIX_SCHEME
private static final String VERSION
private static final org.slf4j.Logger log
public static final long NO_TIMEOUT
private static final long DEFAULT_CONNECT_TIMEOUT_MILLIS
private static final long DEFAULT_READ_TIMEOUT_MILLIS
private static final int DEFAULT_CONNECTION_POOL_SIZE
private static final org.glassfish.jersey.client.ClientConfig DEFAULT_CONFIG
private static final Pattern CONTAINER_NAME_PATTERN
private static final javax.ws.rs.core.GenericType<List<RemovedImage>> REMOVED_IMAGE_LIST
private final javax.ws.rs.client.Client client
private final javax.ws.rs.client.Client noTimeoutClient
private final URI uri
private final AuthConfig authConfig
public DefaultDockerClient(String uri)
uri
- The docker rest api uri.public DefaultDockerClient(URI uri)
uri
- The docker rest api uri.public DefaultDockerClient(URI uri, DockerCertificates dockerCertificates)
uri
- The docker rest api uri.dockerCertificates
- The certificates to use for HTTPS.protected DefaultDockerClient(DefaultDockerClient.Builder builder)
javax.ws.rs.client.Client getClient()
javax.ws.rs.client.Client getNoTimeoutClient()
private org.apache.http.impl.conn.PoolingHttpClientConnectionManager getConnectionManager(DefaultDockerClient.Builder builder)
private org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> getSchemeRegistry(DefaultDockerClient.Builder builder)
public void close()
DockerClient
close
in interface DockerClient
close
in interface Closeable
close
in interface AutoCloseable
public String ping() throws DockerException, InterruptedException
DockerClient
ping
in interface DockerClient
DockerException
InterruptedException
public Version version() throws DockerException, InterruptedException
DockerClient
version
in interface DockerClient
DockerException
InterruptedException
public int auth(AuthConfig authConfig) throws DockerException, InterruptedException
DockerClient
auth
in interface DockerClient
DockerException
InterruptedException
public Info info() throws DockerException, InterruptedException
DockerClient
info
in interface DockerClient
DockerException
InterruptedException
public List<Container> listContainers(DockerClient.ListContainersParam... params) throws DockerException, InterruptedException
DockerClient
listContainers
in interface DockerClient
params
- Container listing and filtering options.DockerException
InterruptedException
public List<Image> listImages(DockerClient.ListImagesParam... params) throws DockerException, InterruptedException
listImages
in interface DockerClient
DockerException
InterruptedException
public ContainerCreation createContainer(ContainerConfig config) throws DockerException, InterruptedException
DockerClient
createContainer
in interface DockerClient
config
- The container configuration.ImageNotFoundException
- if the image was not found (404).DockerException
InterruptedException
public ContainerCreation createContainer(ContainerConfig config, String name) throws DockerException, InterruptedException
DockerClient
createContainer
in interface DockerClient
config
- The container configuration.name
- The container name.ImageNotFoundException
- if the image was not found (404).DockerException
InterruptedException
public void startContainer(String containerId) throws DockerException, InterruptedException
DockerClient
startContainer
in interface DockerClient
containerId
- The id of the container to start.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public void startContainer(String containerId, HostConfig hostConfig) throws DockerException, InterruptedException
DockerClient
startContainer
in interface DockerClient
containerId
- The id of the container to start.hostConfig
- The docker host configuration to use when starting the container.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public void pauseContainer(String containerId) throws DockerException, InterruptedException
DockerClient
pauseContainer
in interface DockerClient
containerId
- The id of the container to pause.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public void unpauseContainer(String containerId) throws DockerException, InterruptedException
DockerClient
unpauseContainer
in interface DockerClient
containerId
- The id of the container to pause.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public void restartContainer(String containerId) throws DockerException, InterruptedException
DockerClient
restartContainer
in interface DockerClient
containerId
- The id of the container to restart.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public void restartContainer(String containerId, int secondsToWaitBeforeRestart) throws DockerException, InterruptedException
DockerClient
restartContainer
in interface DockerClient
containerId
- The id of the container to restart.secondsToWaitBeforeRestart
- number of seconds to wait before killing the container.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public void killContainer(String containerId) throws DockerException, InterruptedException
DockerClient
killContainer
in interface DockerClient
containerId
- The id of the container to kill.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public void stopContainer(String containerId, int secondsToWaitBeforeKilling) throws DockerException, InterruptedException
DockerClient
stopContainer
in interface DockerClient
containerId
- The id of the container to stop.secondsToWaitBeforeKilling
- Time to wait after SIGTERM before sending SIGKILL.DockerException
InterruptedException
public ContainerExit waitContainer(String containerId) throws DockerException, InterruptedException
DockerClient
waitContainer
in interface DockerClient
containerId
- The id of the container to wait for.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public void removeContainer(String containerId) throws DockerException, InterruptedException
DockerClient
removeContainer
in interface DockerClient
containerId
- The id of the container to remove.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public void removeContainer(String containerId, boolean removeVolumes) throws DockerException, InterruptedException
DockerClient
removeContainer
in interface DockerClient
containerId
- The id of the container to remove.removeVolumes
- Whether to remove volumes as well.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public InputStream exportContainer(String containerId) throws DockerException, InterruptedException
DockerClient
exportContainer
in interface DockerClient
containerId
- The id of the container to export.DockerException
InterruptedException
public InputStream copyContainer(String containerId, String path) throws DockerException, InterruptedException
DockerClient
copyContainer
in interface DockerClient
containerId
- The id of the container to copy files from.path
- The path inside of the container to copy. If this is a directory, it will
be copied recursively. If this is a file, only that file will be copied.copy(..., "/usr/share")
will
result in a directory called share
in the tar archive). The directory name is
completely resolved, so copying "/usr/share/././."
will still create a directory called
"share"
in the tar archive. If a single file was copied, that file will be the sole
entry in the tar archive. Copying "."
or equivalently "/"
will result in the
tar archive containing a single folder named after the container ID.DockerException
InterruptedException
public ContainerInfo inspectContainer(String containerId) throws DockerException, InterruptedException
DockerClient
inspectContainer
in interface DockerClient
containerId
- The id of the container to inspect.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public ContainerCreation commitContainer(String containerId, String repo, String tag, ContainerConfig config, String comment, String author) throws DockerException, InterruptedException
DockerClient
commitContainer
in interface DockerClient
containerId
- The id of the container to commit.repo
- repository to commit to.tag
- image tag.config
- ContainerConfig to commit.comment
- commit message.author
- image author.DockerException
InterruptedException
public void pull(String image) throws DockerException, InterruptedException
DockerClient
pull
in interface DockerClient
image
- The image to pull.DockerException
InterruptedException
public void pull(String image, ProgressHandler handler) throws DockerException, InterruptedException
DockerClient
pull
in interface DockerClient
image
- The image to pull.handler
- The handler to use for processing each progress message received from Docker.DockerException
InterruptedException
public void pull(String image, AuthConfig authConfig) throws DockerException, InterruptedException
DockerClient
pull
in interface DockerClient
image
- The image to pull.authConfig
- The authentication config needed to pull the image.DockerException
InterruptedException
public void pull(String image, AuthConfig authConfig, ProgressHandler handler) throws DockerException, InterruptedException
DockerClient
pull
in interface DockerClient
image
- The image to pull.authConfig
- The authentication config needed to pull the image.handler
- The handler to use for processing each progress message received from Docker.DockerException
InterruptedException
public void push(String image) throws DockerException, InterruptedException
DockerClient
push
in interface DockerClient
image
- The image to push.DockerException
InterruptedException
public void push(String image, ProgressHandler handler) throws DockerException, InterruptedException
DockerClient
push
in interface DockerClient
image
- The image to push.handler
- The handler to use for processing each progress message received from Docker.DockerException
InterruptedException
public void tag(String image, String name) throws DockerException, InterruptedException
DockerClient
tag
in interface DockerClient
image
- The image to tag.name
- The new name that will be applied to the image.DockerException
InterruptedException
public String build(Path directory, DockerClient.BuildParameter... params) throws DockerException, InterruptedException, IOException
DockerClient
build
in interface DockerClient
directory
- The directory containing the dockerfile.params
- Additional flags to use during build.DockerException
InterruptedException
IOException
public String build(Path directory, String name, DockerClient.BuildParameter... params) throws DockerException, InterruptedException, IOException
DockerClient
build
in interface DockerClient
directory
- The directory containing the dockerfile.name
- The repository name and optional tag to apply to the built image.params
- Additional flags to use during build.DockerException
InterruptedException
IOException
public String build(Path directory, ProgressHandler handler, DockerClient.BuildParameter... params) throws DockerException, InterruptedException, IOException
DockerClient
build
in interface DockerClient
directory
- The directory containing the dockerfile.handler
- The handler to use for processing each progress message received from Docker.params
- Additional flags to use during build.DockerException
InterruptedException
IOException
public String build(Path directory, String name, ProgressHandler handler, DockerClient.BuildParameter... params) throws DockerException, InterruptedException, IOException
DockerClient
build
in interface DockerClient
directory
- The directory containing the dockerfile.name
- The repository name and optional tag to apply to the built image.handler
- The handler to use for processing each progress message received from Docker.params
- Additional flags to use during build.DockerException
InterruptedException
IOException
public ImageInfo inspectImage(String image) throws DockerException, InterruptedException
DockerClient
inspectImage
in interface DockerClient
image
- The image to inspect.ImageNotFoundException
- if the image was not found (404).DockerException
InterruptedException
public List<RemovedImage> removeImage(String image) throws DockerException, InterruptedException
DockerClient
removeImage
in interface DockerClient
image
- The image to remove.ImageNotFoundException
- if the image was not found (404).DockerException
InterruptedException
public List<RemovedImage> removeImage(String image, boolean force, boolean noPrune) throws DockerException, InterruptedException
DockerClient
removeImage
in interface DockerClient
image
- The image to remove.force
- Force image removal.noPrune
- Do not delete untagged parents.ImageNotFoundException
- if the image was not found (404).DockerException
InterruptedException
public LogStream logs(String containerId, DockerClient.LogsParameter... params) throws DockerException, InterruptedException
DockerClient
logs
in interface DockerClient
containerId
- The id of the container to get logs for.params
- Params for controlling what streams to get and whether to tail or not.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public LogStream attachContainer(String containerId, DockerClient.AttachParameter... params) throws DockerException, InterruptedException
DockerClient
attachContainer
in interface DockerClient
containerId
- The id of the container to get logs for.params
- Params for controlling what streams to get and whether to tail or not.ContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public String execCreate(String containerId, String[] cmd, DockerClient.ExecParameter... params) throws DockerException, InterruptedException
DockerClient
execCreate
in interface DockerClient
containerId
- The id of the containercmd
- shell commandContainerNotFoundException
- if the container was not found (404).DockerException
InterruptedException
public LogStream execStart(String execId, DockerClient.ExecStartParameter... params) throws DockerException, InterruptedException
DockerClient
execStart
in interface DockerClient
execId
- exec idExecNotFoundException
- if the exec was not found (404).DockerException
InterruptedException
private javax.ws.rs.client.WebTarget resource()
private javax.ws.rs.client.WebTarget noTimeoutResource()
private <T> T request(String method, javax.ws.rs.core.GenericType<T> type, javax.ws.rs.client.WebTarget resource, javax.ws.rs.client.Invocation.Builder request) throws DockerException, InterruptedException
DockerException
InterruptedException
private <T> T request(String method, Class<T> clazz, javax.ws.rs.client.WebTarget resource, javax.ws.rs.client.Invocation.Builder request) throws DockerException, InterruptedException
DockerException
InterruptedException
private <T> T request(String method, Class<T> clazz, javax.ws.rs.client.WebTarget resource, javax.ws.rs.client.Invocation.Builder request, javax.ws.rs.client.Entity<?> entity) throws DockerException, InterruptedException
DockerException
InterruptedException
private void request(String method, javax.ws.rs.client.WebTarget resource, javax.ws.rs.client.Invocation.Builder request) throws DockerException, InterruptedException
DockerException
InterruptedException
private void request(String method, javax.ws.rs.client.WebTarget resource, javax.ws.rs.client.Invocation.Builder request, javax.ws.rs.client.Entity<?> entity) throws DockerException, InterruptedException
DockerException
InterruptedException
private RuntimeException propagate(String method, javax.ws.rs.client.WebTarget resource, Exception e) throws DockerException, InterruptedException
DockerException
InterruptedException
private String message(javax.ws.rs.core.Response response)
private String authHeader() throws DockerException
DockerException
private String authHeader(AuthConfig authConfig) throws DockerException
DockerException
public static DefaultDockerClient.Builder builder()
DefaultDockerClient
builder.public static DefaultDockerClient.Builder fromEnv() throws DockerCertificateException
DefaultDockerClient
builder prepopulated with values loaded
from the DOCKER_HOST and DOCKER_CERT_PATH environment variables.DockerCertificateException
private static String defaultEndpoint()
Copyright © 2015. All rights reserved.