Gavlos
Gavlos

Reputation: 267

How to create container with named volume?

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

Upvotes: 1

Views: 491

Answers (1)

Gavlos
Gavlos

Reputation: 267

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

Upvotes: 5

Related Questions