package com.antonjohansson.geotest.docker;

import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.exceptions.DockerException;
import com.spotify.docker.client.messages.ContainerInfo;

/**
 * Defines a single docker container.
 */
public class DockerContainer implements AutoCloseable
{
    private final DockerClient client;
    private final String containerId;

    /**
     * Constructs a new {@link DockerContainer}.
     *
     * @param client The docker client. Used to close the container.
     * @param containerId The identifier of the container.
     */
    DockerContainer(DockerClient client, String containerId)
    {
        this.client = client;
        this.containerId = containerId;
    }

    public String getContainerId()
    {
        return containerId;
    }

    @Override
    public void close()
    {
        try
        {
            ContainerInfo info = client.inspectContainer(containerId);
            if (info.state().running())
            {
                client.killContainer(containerId);
            }
            client.removeContainer(containerId);
        }
        catch (DockerException | InterruptedException e)
        {
            throw new RuntimeException(e);
        }
    }
}

@@ -37,16 +37,106 @@
 ocker;%0A%0A
+import static com.spotify.docker.client.DockerClient.RemoveContainerParam.removeVolumes;%0A%0A
 import c
@@ -1187,32 +1187,49 @@
 iner(containerId
+, removeVolumes()
 );%0A        %7D%0A   

Remove volumes when removing the container This to avoid leaving dangling volumes