Com.github.dockerjava.api.exception.DockerClientException: 证书路径 (DOCKER_CERT_PATH) '/root/.docker/certs' 不存在 一般讨论

Com.github.dockerjava.api.exception.DockerClientException: Certificate path (DOCKER_CERT_PATH) ‘/root/.docker/certs’ doesn’t exist General Discussions

我尝试在 Centos 7 上制作简单的 Docker-Java 应用程序。构建映像和容器调用成功。这是我的代码:

    public class JavaClient {

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        DockerClientConfig config = DockerClientConfig.createDefaultConfigBuilder()
                    .withRegistryUrl("unix:///var/run/docker.sock")
                    .withDockerCertPath("/root/.docker/certs")
                    .withRegistryUsername("user01")
                    .withRegistryPassword("111111")
                    .withRegistryEmail("user01@naver.com")
                    .build();

        DockerClient dockerClient = DockerClientBuilder.getInstance(config).build();

        System.out.println(dockerClient.versionCmd());

    }

 }

但是我根本找不到 Docker 安全文件。 Docker安装、构建镜像、容器调用都没有问题。但是我不知道Centos 7 中的SSL 文件在哪里。这是异常消息

Exception in thread "main" com.github.dockerjava.api.exception.DockerClientException: Certificate path (DOCKER_CERT_PATH) '/root/.docker/certs' doesn't exist.
at com.github.dockerjava.core.DockerClientConfig.checkDockerCertPath(DockerClientConfig.java:112)
at com.github.dockerjava.core.DockerClientConfig.(DockerClientConfig.java:85)
at com.github.dockerjava.core.DockerClientConfig$DockerClientConfigBuilder.build(DockerClientConfig.java:432)
at com.aaa.docker.JavaClient.main(JavaClient.java:18)

您可以只创建空目录 '/root/.docker/certs'.

我找到了另一个不需要创建目录的解决方案。 您可以只创建属性,如环境变量,并将 DOCKER_TLS_VERIFY 设置为“0”。在这种情况下,docker 不会查找任何证书。

final Properties properties = new Properties();
    properties.setProperty("DOCKER_TLS_VERIFY", "0");
    properties.setProperty("DOCKER_HOST", "unix:///var/run/docker.sock");
    final DockerClientConfig.DockerClientConfigBuilder configBuilder = new DockerClientConfig.DockerClientConfigBuilder().withProperties(properties);
    return DockerClientBuilder.getInstance(configBuilder).build();