package org.testcontainers;

import com.spotify.docker.client.DefaultDockerClient;
import com.spotify.docker.client.DockerCertificates;
import com.spotify.docker.client.DockerClient;

import java.nio.file.Paths;

import static org.testcontainers.utility.CommandLine.runShellCommand;

/**
 * Created by rnorth on 09/08/2015.
 */
public class SingletonDockerClient {

    private static SingletonDockerClient instance;
    private final DefaultDockerClient client;
    private String dockerHostIpAddress;

    private SingletonDockerClient() {
        try {
            client = customizeBuilderForOs().build();

            String version = client.version().version();
        } catch (Exception e) {
            throw new IllegalStateException("Failed to create Docker client", e);
        }
    }

    public synchronized static SingletonDockerClient instance() {
        if (instance == null) {
            instance = new SingletonDockerClient();
        }

        return instance;
    }

    public DockerClient client() {
        return client;
    }

    public String dockerHostIpAddress() {
        return dockerHostIpAddress;
    }

    private DefaultDockerClient.Builder customizeBuilderForOs() throws Exception {
        if (System.getProperty("os.name").toLowerCase().contains("mac")) {

            DefaultDockerClient.Builder builder = DefaultDockerClient.builder();

            // Running on a Mac therefore use boot2docker
            runShellCommand("/usr/local/bin/boot2docker", "up");
            dockerHostIpAddress = runShellCommand("/usr/local/bin/boot2docker", "ip");

            builder.uri("https://" + dockerHostIpAddress + ":2376")
                    .dockerCertificates(new DockerCertificates(Paths.get(System.getProperty("user.home") + "/.boot2docker/certs/boot2docker-vm")));

            return builder;
        } else {
            dockerHostIpAddress = "127.0.0.1";
            return DefaultDockerClient.fromEnv();
        }
    }
}

@@ -657,24 +657,59 @@
 .version();%0A
+            checkVersion(version);%0A
         %7D ca
@@ -1996,11 +1996,344 @@
  %7D%0A    %7D
+%0A%0A    private void checkVersion(String version) %7B%0A        String%5B%5D splitVersion = version.split(%22%5C%5C.%22);%0A        if (Integer.valueOf(splitVersion%5B0%5D) %3C= 1 && Integer.valueOf(splitVersion%5B1%5D) %3C 6) %7B%0A            throw new IllegalStateException(%22Docker version 1.6.0+ is required, but version %22 + version + %22 was found%22);%0A        %7D%0A    %7D
 %0A%7D%0A

Add explicit docker version check for v1.6.0+