### Start a Docker Container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This example shows how to start a previously created or stopped Docker container. The container is identified by its ID. ```java docker.startContainer("containerID"); ``` -------------------------------- ### Exec Create, Start, and Inspect Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Shows how to create an exec instance within a running container, start it to execute a command, and then inspect its state and exit code. ```java final String execId = docker.execCreate(containerId, new String[]{"sh", "-c", "exit 2"}).id(); try (final LogStream stream = docker.execStart(execId)) { stream.readFully(); } final ExecState state = docker.execInspect(execId); assertThat(state.id(), is(execId)); assertThat(state.running(), is(false)); assertThat(state.exitCode(), is(2)); assertThat(state.openStdin(), is(true)); assertThat(state.openStderr(), is(true)); assertThat(state.openStdout(), is(true)); } ``` -------------------------------- ### Java Docker Client Comprehensive Usage Example Source: https://github.com/spotify/docker-client/blob/master/README.md A comprehensive example demonstrating how to use the Spotify Docker Client in Java. It covers creating a client, pulling an image, configuring port bindings, creating and starting a container, inspecting its state, executing commands inside it, and finally killing and removing the container. ```Java // Create a client based on DOCKER_HOST and DOCKER_CERT_PATH env vars final DockerClient docker = DefaultDockerClient.fromEnv().build(); // Pull an image docker.pull("busybox"); // Bind container ports to host ports final String[] ports = {"80", "22"}; final Map> portBindings = new HashMap<>(); for (String port : ports) { List hostPorts = new ArrayList<>(); hostPorts.add(PortBinding.of("0.0.0.0", port)); portBindings.put(port, hostPorts); } // Bind container port 443 to an automatically allocated available host port. List randomPort = new ArrayList<>(); randomPort.add(PortBinding.randomPort("0.0.0.0")); portBindings.put("443", randomPort); final HostConfig hostConfig = HostConfig.builder().portBindings(portBindings).build(); // Create container with exposed ports final ContainerConfig containerConfig = ContainerConfig.builder() .hostConfig(hostConfig) .image("busybox").exposedPorts(ports) .cmd("sh", "-c", "while :; do sleep 1; done") .build(); final ContainerCreation creation = docker.createContainer(containerConfig); final String id = creation.id(); // Inspect container final ContainerInfo info = docker.inspectContainer(id); // Start container docker.startContainer(id); // Exec command inside running container with attached STDOUT and STDERR final String[] command = {"sh", "-c", "ls"}; final ExecCreation execCreation = docker.execCreate( id, command, DockerClient.ExecCreateParam.attachStdout(), DockerClient.ExecCreateParam.attachStderr()); final LogStream output = docker.execStart(execCreation.id()); final String execOutput = output.readFully(); // Kill container docker.killContainer(id); // Remove container docker.removeContainer(id); // Close the docker client docker.close(); ``` -------------------------------- ### Create a volume Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Provides examples for creating Docker volumes, both with specified names, drivers, and labels, and as anonymous volumes. ```java final Volume toCreate = Volume.builder() .name("volumeName") .driver("local") .labels(ImmutableMap.of("foo", "bar")) .build(); final Volume created = docker.createVolume(toCreate); ``` ```java final Volume created = docker.createVolume(); ``` -------------------------------- ### Create a Docker Container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This example demonstrates how to create a new Docker container. The ContainerConfig.builder() is used to define the container's configuration before creation. ```java final ContainerCreation container = docker.createContainer(ContainerConfig.builder().build()); ``` -------------------------------- ### Monitor Docker's events Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Illustrates how to subscribe to Docker events, such as container creation and start events, and verify their details using an event stream. ```java docker.pull("busybox:latest"); final EventStream eventStream = docker.events(); final ContainerConfig config = ContainerConfig.builder() .image("busybox:latest") .build(); final ContainerCreation container = docker.createContainer(config, randomName()); docker.startContainer(container.id()); final Event createEvent = eventStream.next(); assertThat(createEvent.status(), equalTo("create")); assertThat(createEvent.id(), equalTo(container.id())); assertThat(createEvent.from(), startsWith("busybox:")); assertThat(createEvent.time(), notNullValue()); final Event startEvent = eventStream.next(); assertThat(startEvent.status(), equalTo("start")); assertThat(startEvent.id(), equalTo(container.id())); assertThat(startEvent.from(), startsWith("busybox:")); assertThat(startEvent.time(), notNullValue()); eventStream.close(); ``` -------------------------------- ### Restart a Docker Container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This example shows how to restart a Docker container. An optional parameter allows specifying a delay in seconds before the container is restarted. ```java docker.restartContainer("containerID"); // or with a seconds to wait before restarting parameter docker.restartContainer("containerID", 10); ``` -------------------------------- ### Get Docker Container Resource Stats Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This example shows how to retrieve resource usage statistics for a Docker container. The method returns a ContainerStats object containing metrics like CPU, memory, and network usage. ```java final ContainerStats stats = docker.stats("containerID"); ``` -------------------------------- ### Unpause a Docker Container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This example shows how to unpause a previously paused Docker container, resuming its processes. ```java docker.unpauseContainer("containerID"); ``` -------------------------------- ### List Processes in Docker Container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This example shows how to list the processes running inside a specified Docker container. It allows passing additional arguments to the 'ps' command for more specific process filtering. ```java final TopResults topResults = docker.topContainer("containerID", "ps_args"); ``` -------------------------------- ### Attach a container to an existing network Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Connects a specified container to an existing Docker network. This operation should ideally be performed before starting the container. ```java docker.connectToNetwork("containerID", "networkID"); ``` -------------------------------- ### Rename a Docker Container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This example shows how to rename an existing Docker container. Both the old and new container IDs (or names) are provided as arguments. ```java docker.renameContainer("oldContainerID", "newContainerID"); ``` -------------------------------- ### Inspect Docker Container Filesystem Changes Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This example shows how to inspect changes made to a Docker container's filesystem. The method returns a list of ContainerChange objects, detailing additions, deletions, or modifications. ```java final List changes = docker.inspectContainerChanges("containerId"); ``` -------------------------------- ### Get the history of an image Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Retrieves the history of a Docker image, showing its layers and commands. ```java final List imageHistoryList = docker.history("imageID"); ``` -------------------------------- ### Get a tarball containing all images in a repository Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Shows how to save a specific Docker image as a tarball to a local file, demonstrating the process of streaming image data to an output file. ```java final File imageFile = save(BUSYBOX); assertTrue(imageFile.length() > 0); final File tmpDir = new File(System.getProperty("java.io.tmpdir")); assertTrue("Temp directory " + tmpDir.getAbsolutePath() + " does not exist", tmpDir.exists()); final File imageFile = new File(tmpDir, "busybox-" + System.nanoTime() + ".tar"); imageFile.createNewFile(); imageFile.deleteOnExit(); final byte[] buffer = new byte[2048]; int read; try (OutputStream imageOutput = new BufferedOutputStream(new FileOutputStream(imageFile))) { try (InputStream imageInput = docker.save("busybox")) { while ((read = imageInput.read(buffer)) > -1) { imageOutput.write(buffer, 0, read); } } } ``` -------------------------------- ### Get a tarball containing all images Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Demonstrates how to retrieve a single tarball containing multiple specified Docker images, allowing for processing of the combined image stream. ```java try (InputStream imageInput = docker.saveMultiple("image0", "image1")) { while ((read = imageInput.read(buffer)) > -1) { // Do stuff with the tar stream of images } } ``` -------------------------------- ### Wait for Docker Container Exit Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This example shows how to wait for a Docker container to exit. The method blocks until the specified container stops, returning its exit status. ```java final ContainerExit exit = docker.waitContainer("containerID"); ``` -------------------------------- ### Get an archive of a filesystem resource in a container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Retrieves an archive (TAR stream) of a specified file or directory within a container, allowing processing of its contents. ```java try (final TarArchiveInputStream tarStream = new TarArchiveInputStream(docker.archiveContainer("containerID", "/file/path"))) { TarArchiveEntry entry; while ((entry = tarStream.getNextTarEntry()) != null) { // Do stuff with the files in the stream } } ``` -------------------------------- ### Get Docker Container Logs Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This snippet demonstrates how to retrieve logs from a Docker container. It uses a LogStream to read stdout and stderr, ensuring all logs are captured. The stream is automatically closed after reading. ```java final String logs; try (LogStream stream = client.logs("containerID", LogsParam.stdout(), LogsParam.stderr())) { logs = stream.readFully(); } ``` -------------------------------- ### Create DockerClient from environment variables or builder Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Demonstrates how to initialize a DockerClient instance using environment variables (DOCKER_HOST, DOCKER_CERT_PATH) or a builder pattern for custom configuration. Both methods return a builder for further customization. ```java // Create a client based on DOCKER_HOST and DOCKER_CERT_PATH env vars final DockerClient docker = DefaultDockerClient.fromEnv().build(); // or use the builder final DockerClient docker = DefaultDockerClient.builder() // Set various options .build(); ``` -------------------------------- ### Create an image Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Creates a Docker image either by pulling it from a registry with authentication or by loading it from a local file stream. ```java // By pulling final RegistryAuth registryAuth = RegistryAuth.builder() .email(AUTH_EMAIL) .username(AUTH_USERNAME) .password(AUTH_PASSWORD) .build(); docker.pull("dxia2/scratch-private:latest", registryAuth); // or by loading from a source final File imageFile = new File("/path/to/image/file"); final String image = "busybox-test" + System.nanoTime(); try (InputStream imagePayload = new BufferedInputStream(new FileInputStream(imageFile))) { docker.create(image, imagePayload); } ``` -------------------------------- ### Build image from a Dockerfile Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Builds a Docker image from a Dockerfile located at a specified path, with progress handling. ```java final AtomicReference imageIdFromMessage = new AtomicReference<>(); final String returnedImageId = docker.build( Paths.get(dockerDirectory), "test", new ProgressHandler() { @Override public void progress(ProgressMessage message) throws DockerException { final String imageId = message.buildImageId(); if (imageId != null) { imageIdFromMessage.set(imageId); } } }); ``` -------------------------------- ### Create a new image from a container's changes Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Demonstrates how to pull an image, create a container, commit its changes to a new image, and then inspect the new image's properties. ```java // Pull image docker.pull("busybox:latest"); // Create container final ContainerConfig config = ContainerConfig.builder() .image("busybox:latest") .build(); final String name = randomName(); final ContainerCreation creation = docker.createContainer(config, name); final String id = creation.id(); final String tag = "foobar"; final ContainerCreation newContainer = docker.commitContainer( id, "mosheeshel/busybox", tag, config, "CommitedByTest-" + tag, "newContainer"); final ImageInfo imageInfo = docker.inspectImage(newContainer.id()); assertThat(imageInfo.author(), is("newContainer")); assertThat(imageInfo.comment(), is("CommitedByTest-" + "foobar")); ``` -------------------------------- ### Load a tarball with a set of images and tags into Docker Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Explains how to load a tarball containing Docker images and tags into the Docker daemon from a local file. ```java final File tarFileWithMultipleImages = new File("/path/to/tarball"); try (InputStream imagePayload = new BufferedInputStream(new FileInputStream(tarFileWithMultipleImages))) { docker.load(InputStream imagePayload); } ``` -------------------------------- ### List volumes Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Illustrates how to retrieve a list of all Docker volumes, including any associated warnings. ```java final VolumeList volumeList = docker.listVolumes(); final List warnings = volumeList.warnings(); final List volumes = volumeList.volumes(); ``` -------------------------------- ### Mounting Host Directories in Docker Containers with Java Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Demonstrates how to use `HostConfig.Builder` and `Bind` objects to mount host directories into Docker containers. It covers direct string binds, creating `Bind` objects for specific paths and read-only options, and using pre-existing `Volume` objects. Also shows how to declare a volume inside the container without host binding. ```java final HostConfig hostConfig = HostConfig.builder() .appendBinds("/local/path:/remote/path") .appendBinds(Bind.from("/another/local/path") .to("/another/remote/path") .readOnly(true) .build()) .appendBinds(Bind.from(aVolume) .to("/yet/another/remote/path") .readOnly(false) .build()) .build(); final ContainerConfig volumeConfig = ContainerConfig.builder() .image("busybox:latest") .volumes("/foo") // This volume will not mount any host directory .hostConfig(hostConfig) .build(); ``` -------------------------------- ### Push an image on the registry Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Pushes a Docker image to a configured registry. ```java docker.push("imageID"); ``` -------------------------------- ### Create a network Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Creates a new Docker network with specified configuration, such as name, attachability, and duplicate checking. ```java NetworkConfig networkConfig = NetworkConfig.builder() .checkDuplicate(true) .attachable(true) .name("newNetwork") .build(); docker.createNetwork(networkConfig); ``` -------------------------------- ### Run Maven Tests for Spotify Docker Client Source: https://github.com/spotify/docker-client/blob/master/README.md Execute the test suite for the Spotify Docker Client using Maven. Be aware that tests create many containers; regular cleanup with `docker rm $(docker ps -aq)` is recommended to manage resources. ```sh mvn test ``` -------------------------------- ### Show the docker version information Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Retrieves version information about the Docker daemon and client. ```java final Version version = docker.version(); ``` -------------------------------- ### Download Docker Client via Maven Source: https://github.com/spotify/docker-client/blob/master/README.md Instructions to include the Spotify Docker Client as a dependency in a Maven project. Replace 'LATEST-VERSION' with the actual version number to use the desired version. ```XML com.spotify docker-client LATEST-VERSION ``` -------------------------------- ### Search images Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Searches for Docker images on configured registries based on a query string. ```java final List searchResult = docker.searchImages("busybox"); ``` -------------------------------- ### Tag an image into a repository Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Tags an existing Docker image with a new name and optional force-reassignment to a different image. ```java docker.pull("busybox:latest"); final String name = "testRepo/tagForce:sometag"; // Assign name to first image docker.tag("busybox:latest", name); // Force-re-assign tag to another image docker.tag("busybox:buildroot-2014.02", name, true); ``` -------------------------------- ### List images Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Lists Docker images, optionally filtered by labels or other criteria. ```java final List quxImages = docker.listImages(ListImagesParam.withLabel("foo", "qux")); ``` -------------------------------- ### Display system-wide information Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Retrieves system-wide information about the Docker daemon. ```java final Info info = docker.info(); ``` -------------------------------- ### Inspect a volume Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Shows how to retrieve detailed information about a specific Docker volume by its name. ```java final Volume volume = docker.inspectVolume("volumeName"); ``` -------------------------------- ### Add Standard Maven Dependency for Spotify Docker Client Source: https://github.com/spotify/docker-client/blob/master/README.md This XML snippet provides the standard Maven dependency configuration for including the Spotify Docker Client in a project. Use this when no specific shading requirements are present. ```xml com.spotify docker-client 3.5.12 ``` -------------------------------- ### Exec Resize Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Demonstrates how to resize the TTY of an exec instance within a Docker container. ```java final int height = 10; final int width = 10; docker.execResizeTty("execID", height, width); ``` -------------------------------- ### Perform Local Maven Release for Spotify Docker Client Source: https://github.com/spotify/docker-client/blob/master/README.md For project maintainers, this command facilitates a local build and release process, uploading the JAR to Sonatype. It requires specifying a GPG key ID for artifact signing and can optionally skip tests. ```sh mvn clean [-DskipTests -Darguments=-DskipTests] -Dgpg.keyname= release:prepare release:perform ``` -------------------------------- ### Connect DockerClient using Unix socket Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Illustrates how to connect to a Docker daemon via a Unix socket. This feature is available on Linux systems since v2.5.0 of the client library. ```java final DockerClient docker = new DefaultDockerClient("unix:///var/run/docker.sock"); ``` -------------------------------- ### Connect DockerClient using HTTPS with client-server authentication Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Shows how to establish an HTTPS connection to a Docker instance with client-server authentication. This approach is similar to using the DOCKER_CERT_PATH environment variable for secure connections. ```java final DockerClient docker = DefaultDockerClient.builder() .uri(URI.create("https://boot2docker:2376")) .dockerCertificates(new DockerCertificates(Paths.get("/Users/rohan/.docker/boot2docker-vm/"))) .build(); ``` -------------------------------- ### Check auth configuration Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Authenticates with a Docker registry using provided credentials and returns the HTTP status code. ```java final RegistryAuth registryAuth = RegistryAuth.builder() .email(AUTH_EMAIL) .username(AUTH_USERNAME) .password(AUTH_PASSWORD) .build(); final int statusCode = docker.auth(registryAuth); assertThat(statusCode, equalTo(200)); ``` -------------------------------- ### Export a Docker Container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This snippet demonstrates how to export a Docker container's filesystem as a tar archive. It then iterates through the entries in the tar stream to list the files contained within the exported image. ```java ImmutableSet.Builder files = ImmutableSet.builder(); try (TarArchiveInputStream tarStream = new TarArchiveInputStream(docker.exportContainer(id))) { TarArchiveEntry entry; while ((entry = tarStream.getNextTarEntry()) != null) { files.add(entry.getName()); } } ``` -------------------------------- ### Ping the docker server Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Pings the Docker daemon to check its availability and returns 'OK' on success. ```java final String pingResponse = docker.ping(); assertThat(pingResponse, equalTo("OK")); ``` -------------------------------- ### Attach to a Docker Container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This snippet illustrates how to attach to a Docker container to stream its logs and output. It allows specifying which streams (stdout, stderr) to capture and whether to stream continuously. ```java final String logs; try (LogStream stream = docker.attachContainer(volumeContainer, AttachParameter.LOGS, AttachParameter.STDOUT, AttachParameter.STDERR, AttachParameter.STREAM)) { logs = stream.readFully(); } ``` -------------------------------- ### Inspect a Docker Container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This snippet illustrates how to inspect a specific Docker container using its ID. The method returns detailed information about the container's state, configuration, and resources. ```java final ContainerInfo info = docker.inspectContainer("containerID"); ``` -------------------------------- ### List Docker Containers Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This snippet shows how to retrieve a list of Docker containers. By default, only running containers are returned. An additional parameter can be used to list all containers, including stopped ones. ```java final List containers = docker.listContainers(); // List all containers. Only running containers are shown by default. final List containers = docker.listContainers(ListContainersParam.allContainers()); ``` -------------------------------- ### Docker Client Registry Authentication Suppliers Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This section outlines the available implementations of the RegistryAuthSupplier interface, which provides authentication information for Docker operations like building, pushing, or pulling images, and using Swarm. Users can also implement this interface for custom authentication logic. Since version 8.7.0, DefaultDockerClient automatically enables ConfigFileRegistryAuthSupplier if no other authentication methods are explicitly configured. ```APIDOC RegistryAuthSupplier Interface Implementations: - auth.ConfigFileRegistryAuthSupplier: Reads authentication info from ~/.dockercfg or ~/.docker/config.json. - auth.FixedRegistryAuthSupplier: Uses a fixed instance of the RegistryAuth and RegistryConfigs POJOs. - auth.gcr.ContainerRegistryAuthSupplier: Programmatically fetches access tokens for Google Container Registry based on given Google Cloud account credentials. - auth.MultiRegistryAuthSupplier: Can be used to combine multiple other implementations. Automatic Configuration: Since version 8.7.0, DefaultDockerClient automatically enables ConfigFileRegistryAuthSupplier if none of the other authentication-related methods in the DefaultDockerClient.Builder class (dockerAuth(boolean), registryAuth(RegistryAuth), or registryAuthSupplier(RegistryAuthSupplier)) are used. ``` -------------------------------- ### Kill a Docker Container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This snippet demonstrates how to immediately kill a running Docker container. This action forcefully terminates the container process. ```java docker.killContainer("containerID"); ``` -------------------------------- ### Stop a Docker Container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This snippet demonstrates how to stop a running Docker container. An optional timeout can be provided to specify how long to wait before forcefully killing the container. ```java docker.stopContainer("containerID", 10); // kill after 10 seconds ``` -------------------------------- ### Inspect an image Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Retrieves detailed information about a Docker image by its ID. ```java final ImageInfo info = docker.inspectImage("imageID") ``` -------------------------------- ### Inspect a network Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Retrieves detailed information about a Docker network by its ID. ```java docker.inspectNetwork("networkID"); ``` -------------------------------- ### Create secret Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Creates a new Docker secret with a specified name and base64-encoded data. ```java final SecretSpec secret = SecretSpec.builder().name("asecret").data(base64encodeddata).build(); docker.createSecret(secret); ``` -------------------------------- ### Add Shaded Maven Dependency for Spotify Docker Client Source: https://github.com/spotify/docker-client/blob/master/README.md This Maven dependency configuration includes the shaded version of the Spotify Docker Client. It is crucial for projects using Jersey 1.x to prevent dependency conflicts with Jersey 2.x, which is bundled with `docker-client`. ```xml com.spotify docker-client shaded 3.5.12 ``` -------------------------------- ### Remove a volume Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Demonstrates how to remove a Docker volume, either by its name or by an object reference to the volume. ```java docker.removeVolume("volumeName"); ``` ```java docker.removeVolume(volume); ``` -------------------------------- ### Docker API Changes: Mounts vs. Volumes (v1.20+) Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Documents the change in Docker Remote API version 1.20 (Docker 1.8.x) where container volume information is returned under the 'Mounts' key instead of 'Volumes'. It notes the deprecation of `ContainerInfo.volumes()` and recommends using `ContainerInfo.mounts()` for retrieving volume details. ```APIDOC Docker API Version 1.20 (Docker 1.8.x) Changes: - Volume information key changed from "Volumes" to "Mounts" - Deprecated: ContainerInfo.volumes() - Recommended: ContainerInfo.mounts() ``` -------------------------------- ### Resize Docker Container TTY Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This snippet demonstrates how to resize the TTY (pseudo-terminal) of a running Docker container. This is useful for interactive sessions where terminal dimensions need to be adjusted. ```java final int height = 10; final int width = 10; docker.resizeTty("containerID", height, width); ``` -------------------------------- ### Copy files or folders from a container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Copies files or folders from a specified container. Note: This method is deprecated in favor of `archiveContainer`. ```java ImmutableSet.Builder files = ImmutableSet.builder(); try (TarArchiveInputStream tarStream = new TarArchiveInputStream(docker.copyContainer(id, "/bin"))) { TarArchiveEntry entry; while ((entry = tarStream.getNextTarEntry()) != null) { files.add(entry.getName()); } } ``` -------------------------------- ### Pause a Docker Container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This snippet demonstrates how to pause all processes within a Docker container. Pausing freezes the container's processes without stopping them. ```java docker.pauseContainer("containerID"); ``` -------------------------------- ### Extract an archive of files or folders to a directory in a container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Copies a local file or directory to a specified path within a Docker container. ```java docker.copyToContainer(new java.io.File("/local/path").toPath(), "containerID", "/path/in/container"); ``` -------------------------------- ### Remove an image Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Removes a Docker image by its ID. ```java docker.removeImage("imageID"); ``` -------------------------------- ### Configure Docker Client Connection Pool Size Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md This snippet demonstrates how to modify the default connection pool size for the Docker client. The Apache HTTP client is used under the covers, with a default pool size of 100 concurrent requests. Adjusting this is crucial for applications requiring more concurrent operations, such as waiting on many containers. A DockerTimeoutException is thrown if acquiring a connection from an exhausted pool takes too long. ```java final DockerClient docker = DefaultDockerClient.fromEnv() .connectionPoolSize(SOME_LARGE_NUMBER) .build(); ``` -------------------------------- ### Remove a container Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Removes a Docker container by its ID. ```java docker.removeContainer("containerID"); ``` -------------------------------- ### Remove a network Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Removes a Docker network by its ID. ```java docker.removeNetwork("networkID"); ``` -------------------------------- ### Detach a container from a network Source: https://github.com/spotify/docker-client/blob/master/docs/user_manual.md Disconnects a specified container from a Docker network. ```java docker.disconnectFromNetwork("containerID", "networkID"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.