本文整理汇总了Java中com.github.dockerjava.api.command.CreateContainerCmd.withEnv方法的典型用法代码示例。如果您正苦于以下问题:Java CreateContainerCmd.withEnv方法的具体用法?Java CreateContainerCmd.withEnv怎么用?Java CreateContainerCmd.withEnv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.dockerjava.api.command.CreateContainerCmd
的用法示例。
在下文中一共展示了CreateContainerCmd.withEnv方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, WebHealthCheck whc) {
final String serviceNameEnv = SERVICE_PREFIX + whc.exposedPort() + SERVICE_NAME_SUFFIX + "=" + td.getNamed().value();
final String serviceCheckScriptEnv = SERVICE_CHECK_SCRIPT + "=`which curl` -f "
+ (whc.protocol().equals(WebProtocol.HTTPS) ? "-sSk " : "")
+ whc.protocol().toString().toLowerCase()
+ "://$SERVICE_IP:$SERVICE_PORT"
+ whc.endpoint();
final String serviceCheckIntervalEnv = SERVICE_CHECK_INTERVAL + "=" + whc.pollingInterval() + "s";
List<String> finalEnv = new ArrayList<>();
List<String> healthCheckEnv = Arrays.asList(serviceNameEnv, serviceCheckScriptEnv, serviceCheckIntervalEnv);
finalEnv.addAll(healthCheckEnv);
String[] env = cmd.getEnv();
if(env != null) {
finalEnv.addAll(Arrays.asList(env));
}
return cmd.withEnv(finalEnv);
}
示例2: startNode
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
public void startNode(String id, BrowserType browserType, String nodeName, String imageId,
String hubIp) {
// Create node if not exist
if (!existsContainer(nodeName)) {
pullImageIfNecessary(imageId, false);
log.debug("Creating container {}", nodeName);
CreateContainerCmd createContainerCmd =
getClient().createContainerCmd(imageId).withName(nodeName);
// TODO make this port configurable
createContainerCmd.withEnv(new String[] { "HUB_PORT_4444_TCP_ADDR=" + hubIp, "HUB_PORT_4444_TCP_PORT=4444" });
createContainerCmd.exec();
log.debug("Container {} started...", nodeName);
} else {
log.debug("Container {} already exists", nodeName);
}
// Start node if stopped
startContainer(nodeName);
}
示例3: beforeContainerCreated
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
public void beforeContainerCreated(DockerAPI api, String workdir, CreateContainerCmd cmd) throws IOException, InterruptedException {
List<String> args = new ArrayList<>();
if (StringUtils.isNotBlank(jnlpLauncher.tunnel)) {
args.addAll(Arrays.asList("-tunnel", jnlpLauncher.tunnel));
}
String nodeName = DockerTransientNode.nodeName(cmd.getName());
args.addAll(Arrays.asList(
"-url", StringUtils.isEmpty(jenkinsUrl) ? Jenkins.getInstance().getRootUrl() : jenkinsUrl,
JnlpSlaveAgentProtocol.SLAVE_SECRET.mac(nodeName),
nodeName));
cmd.withCmd(args.toArray(new String[args.size()]));
String vmargs = jnlpLauncher.vmargs;
if (StringUtils.isNotBlank(vmargs)) {
cmd.withEnv("JAVA_OPT=" + vmargs.trim());
}
if (StringUtils.isNotBlank(user)) {
cmd.withUser(user);
}
}
示例4: build
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, Env t) {
String[] env = cmd.getEnv();
List<String> finalEnv = new ArrayList<>();
finalEnv.addAll(Arrays.asList(t.value()));
if (env != null) {
finalEnv.addAll(Arrays.asList(env));
}
return cmd.withEnv(finalEnv);
}
示例5: run
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
protected String run() throws Exception {
CreateContainerCmd createCmd = dockerClient.createContainerCmd(imageId);
createCmd.withAttachStderr(true).withAttachStdout(true).withName(params.getName());
createCmd.withNetworkMode(bridgeNetworkName.toString());
if (!params.getBinds().isEmpty()) {
createCmd.withBinds(createBinds());
}
if (params.getPortBinds().isEmpty()) {
createCmd.withPublishAllPorts(true);
} else {
createCmd.withExposedPorts(createExposedPorts()).withPortBindings(createPorts());
}
if (params.getCommand().isPresent()) {
createCmd.withCmd(params.getCommand().get());
}
if (!params.getEnvs().isEmpty()) {
String[] envs = params.getEnvs().stream().map(env -> String.format("%s='%s'", env.getName(), env.getValue().get())).toArray(String[]::new);
createCmd.withEnv(envs);
}
try {
return createCmd.exec().getId();
} finally {
createCmd.close();
}
}
示例6: run
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的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());
}
示例7: create
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
@Override
public String create(String image, String name, String[] env, String[] linking) {
DockerClient dockerClient = getClient();
if (image == null || image.trim().length() == 0) {
LOGGER.error("Container's image name to create is empty");
return null;
}
final CreateContainerCmd createContainerCmd = dockerClient.createContainerCmd(image)
.withPublishAllPorts(true)
.withAttachStdout(true)
.withAttachStdin(true)
.withAttachStdin(true)
.withTty(true);
if (linking != null) {
final String linkName = linking[0];
final String linkAlias = linking[1];
final Link link = new Link(linkName, linkAlias);
createContainerCmd.withLinks(link);
}
if (name != null && name.trim().length() > 0) createContainerCmd.withName(name);
if (env != null && env.length > 0) createContainerCmd.withEnv(env);
final CreateContainerResponse createContainerResponse = createContainerCmd.exec();
final String id = createContainerResponse.getId();
return id;
}
示例8: runContainer
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
private Process runContainer() {
try
{
DockerClient client = getClient();
CreateContainerCmd createCmd = client.createContainerCmd(testExtension.getImage().toString())
.withTty(false)
.withStdinOpen(true)
.withStdInOnce(true)
.withWorkingDir(directory.getAbsolutePath());
createCmd.withEnv(getEnv());
String user = testExtension.getUser();
if (user != null)
createCmd.withUser(user);
bindVolumes(createCmd);
List<String> cmdLine = new ArrayList<String>();
cmdLine.add(command);
cmdLine.addAll(arguments);
createCmd.withCmd(cmdLine);
invokeIfNotNull(testExtension.getBeforeContainerCreate(), createCmd, client);
String containerId = createCmd.exec().getId();
invokeIfNotNull(testExtension.getAfterContainerCreate(), containerId, client);
invokeIfNotNull(testExtension.getBeforeContainerStart(), containerId, client);
client.startContainerCmd(containerId).exec();
invokeIfNotNull(testExtension.getAfterContainerStart(), containerId, client);
if (!client.inspectContainerCmd(containerId).exec().getState().getRunning()) {
throw new RuntimeException("Container "+containerId+" not running!");
}
Process proc = new DockerizedProcess(client, containerId, testExtension.getAfterContainerStop());
return proc;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
示例9: 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);
}
}
示例10: call
import com.github.dockerjava.api.command.CreateContainerCmd; //导入方法依赖的package包/类
public String call() throws Exception {
DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, null);
CreateContainerCmd cfgCmd = client.createContainerCmd(imageRes);
if (commandRes != null) {
cfgCmd.withCmd(commandRes);
}
cfgCmd.withHostName(hostNameRes);
cfgCmd.withName(containerNameRes);
HostConfig hc = new HostConfig();
cfgCmd.withLinks(LinkUtils.parseLinks(linksRes).getLinks());
if (envVarsRes != null) {
cfgCmd.withEnv(envVarsRes);
}
if (exposedPortsRes != null && !exposedPortsRes.isEmpty()) {
final ExposedPort[] ports;
String[] exposedPortsSplitted = exposedPortsRes.split(",");
ports = new ExposedPort[exposedPortsSplitted.length];
for (int i = 0; i < ports.length; i++) {
ports[i] = ExposedPort.parse(exposedPortsSplitted[i]);
}
cfgCmd.withExposedPorts(ports);
}
if (cpuSharesRes != null) {
cfgCmd.withCpuShares(cpuSharesRes);
}
if (memoryLimitRes != null) {
cfgCmd.withMemory(memoryLimitRes);
}
if (dnsRes != null) {
cfgCmd.withDns(dnsRes);
}
if (extraHostsRes != null) {
cfgCmd.withExtraHosts(extraHostsRes);
}
if (portBindingsRes != null) {
cfgCmd.withPortBindings(PortBindingParser.parse(portBindingsRes));
}
if (bindMountsRes != null) {
cfgCmd.withBinds(BindParser.parse(bindMountsRes));
}
if (alwaysRestart) {
cfgCmd.withRestartPolicy(RestartPolicy.alwaysRestart());
}
CreateContainerResponse resp = cfgCmd.withPublishAllPorts(publishAllPorts).withPrivileged(privileged).exec();
InspectContainerResponse inspectResp = client.inspectContainerCmd(resp.getId()).exec();
ObjectMapper mapper = new ObjectMapper();
String serialized = mapper.writeValueAsString(inspectResp);
return serialized;
}