1

我尝试在 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)
4

1 回答 1

1

您可以只创建空目录'/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();
于 2016-08-03T09:32:13.853 回答