com.github.dockerjava.api.model.AccessMode Java Examples

The following examples show how to use com.github.dockerjava.api.model.AccessMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElasticsearchAuthSystemTest.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * Use an alpine image to write files to the VM/docker host. Then all the containers can mount that DIR and get access to the passwd files.
 */
private void writePasswordFileToVM() {
    // Mesos password
    CreateContainerResponse exec = dockerClient.createContainerCmd(ALPINE)
            .withBinds(new Bind(SECRET_FOLDER, new Volume(SECRET_FOLDER), AccessMode.rw))
            .withCmd("rm", "-r", SECRET_FOLDER)
            .exec();
    dockerClient.startContainerCmd(exec.getId()).exec();
    exec = dockerClient.createContainerCmd(ALPINE)
            .withBinds(new Bind(SECRET_FOLDER, new Volume(SECRET_FOLDER), AccessMode.rw))
            .withCmd("sh", "-c", "echo -n testRole secret | tee -a " + SECRET_FOLDER + SECRET)
            .exec();
    dockerClient.startContainerCmd(exec.getId()).exec();

    // Framework password
    // Note that the definition is slightly different. There is no username specified in the file. Just the password.
    exec = dockerClient.createContainerCmd(ALPINE)
            .withBinds(new Bind(SECRET_FOLDER, new Volume(SECRET_FOLDER), AccessMode.rw))
            .withCmd("sh", "-c", "echo -n secret | tee -a " + SECRET_FOLDER + FRAMEWORKPASSWD)
            .exec();
    dockerClient.startContainerCmd(exec.getId()).exec();
}
 
Example #2
Source File: CustomSettingsDockerSystemTest.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected CreateContainerCmd dockerCommand() {
    return dockerClient
            .createContainerCmd(TEST_CONFIG.getSchedulerImageName())
            .withName(TEST_CONFIG.getSchedulerName() + "_" + clusterId + "_" + new SecureRandom().nextInt())
            .withBinds(new Bind(CUSTOM_CONFIG_PATH, new Volume(CUSTOM_CONFIG_PATH), AccessMode.ro))
            .withEnv("JAVA_OPTS=-Xms128m -Xmx256m")
            .withCmd(
                    ElasticsearchCLIParameter.ELASTICSEARCH_SETTINGS_LOCATION, configPath,
                    ZookeeperCLIParameter.ZOOKEEPER_MESOS_URL, getZookeeperMesosUrl(),
                    ELASTICSEARCH_CPU, "0.25",
                    ELASTICSEARCH_RAM, "256",
                    ELASTICSEARCH_DISK, "10",
                    USE_IP_ADDRESS, "true"
            );
}
 
Example #3
Source File: DockerImageExecutor.java    From hawkular-apm with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #4
Source File: LogstashSchedulerContainer.java    From logstash with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: BindVolumeCreateContainerPostProcessor.java    From Dolphin with Apache License 2.0 4 votes vote down vote up
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);
}