本文整理汇总了Java中com.github.dockerjava.api.model.AccessMode类的典型用法代码示例。如果您正苦于以下问题:Java AccessMode类的具体用法?Java AccessMode怎么用?Java AccessMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccessMode类属于com.github.dockerjava.api.model包,在下文中一共展示了AccessMode类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import com.github.dockerjava.api.model.AccessMode; //导入依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, Volume v) {
Bind[] binds = cmd.getBinds();
String hostPath = v.useClasspath()
? Thread.currentThread().getContextClassLoader()
.getResource(v.host()).getPath()
: v.host();
Bind bind = new Bind(hostPath,
new com.github.dockerjava.api.model.Volume(v.container()),
AccessMode.fromBoolean(v.accessMode().equals(Volume.AccessMode.RW)));
List<Bind> bindsList = new ArrayList<>();
if(binds != null) {
bindsList.addAll(Arrays.asList(binds));
}
bindsList.add(bind);
return cmd.withBinds(bindsList);
}
示例2: run
import com.github.dockerjava.api.model.AccessMode; //导入依赖的package包/类
@Override
public List<String> run(TestEnvironment testEnvironment) {
String hostOsMountDir = System.getProperties().getProperty("buildDirectory");
CreateContainerCmd containerBuilder = dockerClient.createContainerCmd(testEnvironment.getImage())
.withBinds(new Bind(hostOsMountDir, new Volume(Constants.HAWKULAR_APM_AGENT_DIRECTORY),
AccessMode.ro, SELContext.shared),
new Bind(scenarioDirectory, new Volume(Constants.HAWKULAR_APM_TEST_DIRECTORY),
AccessMode.ro, SELContext.shared))
.withExtraHosts(Constants.HOST_ADDED_TO_ETC_HOSTS + ":" + apmBindAddress);
if (userDefinedNetwork) {
if (network == null) {
throw new IllegalStateException("Create network before running environment");
}
containerBuilder.withNetworkMode(network.getName());
}
containerBuilder.withEnv(apmEnvVariables(testEnvironment.getType()));
if (testEnvironment.isPull()) {
log.info("Pulling image...");
dockerClient.pullImageCmd(testEnvironment.getImage()).exec(new PullImageResultCallback()).awaitSuccess();
}
CreateContainerResponse containerResponse = containerBuilder.exec();
log.info(String.format("Starting docker container: %s", containerResponse));
try {
dockerClient.startContainerCmd(containerResponse.getId()).exec();
} catch (DockerException ex) {
log.severe(String.format("Could not create or start docker container: %s", containerResponse));
throw new EnvironmentException("Could not create or start docker container.", ex);
}
return Arrays.asList(containerResponse.getId());
}
示例3: dockerCommand
import com.github.dockerjava.api.model.AccessMode; //导入依赖的package包/类
@Override
protected CreateContainerCmd dockerCommand() {
final String[] cmd = asList(
"--mesos.master=" + mesosMasterIpAddress + ":5050",
"--mesos.zookeeper.server=" + zookeeperIpAddress + ":2181",
mesosRole.map(role -> "--mesos-role=" + role).orElse(null),
"--enable.failover=false",
elasticsearchHost.map(host -> "--logstash.elasticsearch-host=" + host).orElse(null),
"--executor.heap-size=64",
"--logstash.heap-size=256",
"--enable.docker=" + useDocker,
logstashConfig.map(file -> "--logstash.config-file=/config/" + file.getName()).orElse(null),
withSyslog ? "--enable.syslog=true" : null
).stream().filter(StringUtils::isNotEmpty).toArray(String[]::new);
final CreateContainerCmd containerCmd = dockerClient.createContainerCmd(SCHEDULER_IMAGE);
logstashConfig.ifPresent(file -> {
try {
containerCmd.withBinds(new Bind(file.getParentFile().getCanonicalPath(), new Volume("/config"), AccessMode.ro));
} catch (IOException e) {
throw new IllegalStateException("Path error", e);
}
});
return containerCmd
.withName(SCHEDULER_NAME + "_" + new SecureRandom().nextInt())
.withExposedPorts(ExposedPort.tcp(9092))
.withCmd(cmd);
}
示例4: verify_container_SIMPLE_create_with_ports_and_volumes_and_variables
import com.github.dockerjava.api.model.AccessMode; //导入依赖的package包/类
@Test
public void verify_container_SIMPLE_create_with_ports_and_volumes_and_variables ()
throws Exception {
String imageName = BUSY_BOX;
loadImageIfNeeded( imageName );
String containerName = "/java-simple-" + LocalDateTime.now().format( DateTimeFormatter.ofPattern( "MMM.d-HH.mm.ss" ) );
List<String> entryParameters = Arrays.asList( "nginx", "-g", "daemon off;" );
List<String> cmdParameters = Arrays.asList( "nginx", "-v" );
// ref. https://github.com/docker-java/docker-java/wiki
ExposedPort tcp80 = ExposedPort.tcp( 80 );
List<ExposedPort> exposedList = new ArrayList<>();
// exposedList.add( tcp80 ) ;
// ExposedPort tcp23 = ExposedPort.tcp(23);
Ports portBindings = new Ports();
portBindings.bind( tcp80, Ports.Binding.bindPort( 90 ) );
// portBindings.bind( tcp80, Ports.Binding("") );
List<Volumes> volumes = new ArrayList<>();
Bind javaVolumeBind = new Bind( "/opt/java", new Volume( "/java" ), AccessMode.ro, SELContext.shared );
List<String> environmentVariables = new ArrayList<>();
environmentVariables.add( "JAVA_HOME=/opt/java" );
environmentVariables.add( "WORKING_DIR=/working" );
environmentVariables.add( "JAVA_OPTS=some path" );
List<Ulimit> ulimits = new ArrayList<>();
ulimits.add( new Ulimit( "nofile", 1000, 1000 ) );
ulimits.add( new Ulimit( "nproc", 10, 10 ) );
Map<String, String> jsonLogConfig = new HashMap<>();
jsonLogConfig.put( "max-size", "10m" );
jsonLogConfig.put( "max-file", "2" );
LogConfig logConfig = new LogConfig( LoggingType.JSON_FILE, jsonLogConfig );
CreateContainerResponse container = dockerClient
.createContainerCmd( imageName )
.withName( containerName )
// .withCmd( cmdParameters )
// .withEntrypoint( entryParameters )
.withCpusetCpus( "0-1" )
.withLogConfig( logConfig )
.withCpuPeriod( 400000 )
.withMemory( 20 * CSAP.MB_FROM_BYTES )
.withUlimits( ulimits )
.withExposedPorts( exposedList )
.withPortBindings( portBindings )
.withBinds( javaVolumeBind )
.withHostName( "peter" )
// .withNetworkMode( "host" )
.withEnv( environmentVariables )
.exec();
InspectContainerResponse containerInfo = getContainerStatus( containerName );
ObjectNode containerInfoJson = jacksonMapper.convertValue( containerInfo, ObjectNode.class );
logger.info( "Name: {} , InfoJson: \n {}", containerInfo.getName(), pp( containerInfoJson ) );
dockerClient.startContainerCmd( container.getId() )
.exec();
dockerClient
.removeContainerCmd( container.getId() )
.withRemoveVolumes( true )
.withForce( true )
.exec();
}
示例5: createBind
import com.github.dockerjava.api.model.AccessMode; //导入依赖的package包/类
private Bind createBind(InstanceStartRequest request) {
String outer = configManager.getOuterWebPackageRootDir(request.getAppId(), request.getInstanceIndex());
Volume inner = new Volume(configManager.getInnerWebPackageRootDir());
return new Bind(outer, inner, AccessMode.rw);
}
示例6: defaultAccessMode_blank
import com.github.dockerjava.api.model.AccessMode; //导入依赖的package包/类
@Test
public void defaultAccessMode_blank() {
assertCreatesBinds(input("/host /container"),
expected("/host", "/container", AccessMode.DEFAULT));
}
示例7: defaultAccessMode_colon
import com.github.dockerjava.api.model.AccessMode; //导入依赖的package包/类
@Test
public void defaultAccessMode_colon() {
assertCreatesBinds(input("/host:/container"),
expected("/host", "/container", AccessMode.DEFAULT));
}
示例8: Expected
import com.github.dockerjava.api.model.AccessMode; //导入依赖的package包/类
public Expected(String hostPath, String containerPath, AccessMode accessMode) {
this.hostPath = hostPath;
this.containerPath = containerPath;
this.accessMode = accessMode;
}
示例9: expected
import com.github.dockerjava.api.model.AccessMode; //导入依赖的package包/类
/**
* Designates the arguments as the expected result of parsing.<br>
* For increased readability.
*
* @param hostPath the expected host path of the parsing result
* @param containerPath the expected container path of the parsing result
* @param accessMode the access mode of the parsing result
* @return a container object for the expected values
*/
private static Expected expected(String hostPath, String containerPath, AccessMode accessMode) {
return new Expected(hostPath, containerPath, accessMode);
}