如何使用命名卷创建容器?

huangapple go评论73阅读模式
英文:

How to create container with named volume?

问题

使用docker-java库如何创建带有命名Docker卷的容器?

英文:

How to create container with named docker volume using the docker-java library?

答案1

得分: 4

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

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

    Bind bind = new Bind(namedVolumeName, newVolume);

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

Ok, I found solution:

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

Bind bind = new Bind(namedVolumeName, newVolume);

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

huangapple
  • 本文由 发表于 2020年8月25日 21:47:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/63580286.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定