将Docker Secrets与Spotify Docker Client结合使用

时间:2019-01-29 19:00:46

标签: java spotify-docker-client

我正在使用Spotify的Docker-Client,但是遇到了文档墙。我试图弄清楚如何将已经在环境中创建的Docker机密传递给使用docker-client构建的容器。该文档仅显示了如何创建机密,但是由于机密已经存在,因此它不是很有用。我可以使用listSecrets中的DockerClient获取环境中的机密列表,但是无法将它们从Secret转换为SecretBind。非常感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

通过所有代码spotify/docker-client代码,我发现了这一点。该文档没有显示将Secret传递给Docker Secrets的SecretBind转换为ContainerSpec的方法。

public SecretBind createBind(Secret secret) {
    SecretFile file = SecretFile.builder()
                                .name(secret.secretSpect().name())
                                .uid("0")
                                .gid("0")
                                .build();
    SecretBind bind = SecretBind.builder()
                                .secretName(secret.secretSpec().name())
                                .secretId(secret.id())
                                .file(file)
                                .build();
    return bind;
}