如何用命名卷创建容器?

时间:2020-08-25 13:47:31

标签: java docker-api

如何使用docker-java library使用命名的docker卷创建容器?

1 个答案:

答案 0 :(得分:2)

好的,我找到了解决方法:

Volume newVolume = new Volume("/target");

Bind bind = new Bind(namedVolumeName, newVolume);

CreateContainerResponse container = dockerClient.createContainerCmd(imageId)
    .withName(containerName)
    .withHostConfig(HostConfig.newHostConfig().withBinds(bind))
    .exec();