javadocker-api

How to create container with named volume?


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


Solution

  • 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();