本文整理汇总了Java中com.github.dockerjava.api.command.CreateContainerCmd.withVolumes方法的典型用法代码示例。如果您正苦于以下问题:Java CreateContainerCmd.withVolumes方法的具体用法?Java CreateContainerCmd.withVolumes怎么用?Java CreateContainerCmd.withVolumes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.dockerjava.api.command.CreateContainerCmd
的用法示例。
在下文中一共展示了CreateContainerCmd.withVolumes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createContainer
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
public Container createContainer(Environment env, String containerName, ImageConfiguration imageConf, Image image, String command) throws ContainerizationException {
CreateContainerResponse containerCreateResponse = null;
InspectContainerResponse containerInspectResponse = null;
try {
CreateContainerCmd createContainerCommand = getDockerClient().createContainerCmd(image.getId());
createContainerCommand.withName(containerName);
// keep the container alive
//containerConfig.setCmd(new String[]{"/bin/bash", "/home/synaptiq/run_tomcat.sh", dockerHost, "" + mysqlPort});
if (command != null) {
createContainerCommand.withCmd(command.split(" "));
}
List<ExposedPort> exposedPorts = new ArrayList<ExposedPort>();
if (imageConf.getPorts() != null) {
for (PortConfiguration port : imageConf.getPorts()) {
exposedPorts.add(new ExposedPort("tcp", port.getContainerPort()));
}
}
createContainerCommand.withExposedPorts(exposedPorts.toArray(new ExposedPort[0]));
createContainerCommand.withTty(false);
List<Volume> volumesList = new ArrayList<Volume>();
if (imageConf.getVolumes() != null) {
for (VolumeConfiguration volumeConfiguration : imageConf.getVolumes()) {
volumesList.add(new Volume(volumeConfiguration.getPath()));
}
}
createContainerCommand.withVolumes(volumesList.toArray(new Volume[0]));
if (imageConf.getEnvironment() != null) {
List<String> environmentVariables = new ArrayList<String>();
for (EnvironmentVariableConfiguration evc : imageConf.getEnvironment()) {
environmentVariables.add(evc.getVariable() + "=" + evc.getValue());
}
createContainerCommand.withEnv(environmentVariables.toArray(new String[0]));
}
containerCreateResponse = createContainerCommand.exec();
containerInspectResponse = getDockerClient().inspectContainerCmd(containerCreateResponse.getId()).exec();
DockerContainer dockerContainer = new DockerContainer(containerCreateResponse, containerInspectResponse, image);
return dockerContainer;
} catch(Exception ex) {
if (containerCreateResponse != null) {
try {
getDockerClient().killContainerCmd(containerCreateResponse.getId()).exec();
getDockerClient().removeContainerCmd(containerCreateResponse.getId()).exec();
}
catch(DockerException e) {
throw new ContainerizationException(e);
}
}
throw new ContainerizationException(ex);
}
}