本文整理汇总了Java中com.spotify.docker.client.messages.HostConfig类的典型用法代码示例。如果您正苦于以下问题:Java HostConfig类的具体用法?Java HostConfig怎么用?Java HostConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HostConfig类属于com.spotify.docker.client.messages包,在下文中一共展示了HostConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newContainer
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
@Override
String newContainer(Language language) throws DockerException, InterruptedException {
String name = language.getRunDockerImageName();
if (!DockerOperator.instance().isImageExist(name))
DockerOperator.instance().pull(name);
ContainerConfig config = ContainerConfig.builder()
.networkDisabled(true)
.workingDir("/sandbox")
.image(name)
.cmd("sh", "-c", "while :; do sleep 1; done")
.hostConfig(
HostConfig.builder().binds(HostConfig.Bind.builder()
.from(Constants._WORK_DIR()).to("/sandbox").build())
.oomKillDisable(false).memory(67108864L).memorySwap(67108864L).build()
).build();
String r = DockerOperator.instance().createContainer(config);
map.put(language, r);
return r;
}
示例2: PostgresContainer
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
public PostgresContainer(DockerClient docker, String host) throws InterruptedException, IOException, ClassNotFoundException, DockerException {
Class.forName("org.postgresql.Driver");
this.docker = docker;
this.host = host;
failsafeDockerPull(docker, GOVUK_POSTGRES_IMAGE);
docker.listImages(DockerClient.ListImagesParam.create("name", GOVUK_POSTGRES_IMAGE));
final HostConfig hostConfig = HostConfig.builder().logConfig(LogConfig.create("json-file")).publishAllPorts(true).build();
ContainerConfig containerConfig = ContainerConfig.builder()
.image(GOVUK_POSTGRES_IMAGE)
.hostConfig(hostConfig)
.env("POSTGRES_USER=" + DB_USERNAME, "POSTGRES_PASSWORD=" + DB_PASSWORD)
.build();
containerId = docker.createContainer(containerConfig).id();
docker.startContainer(containerId);
port = hostPortNumber(docker.inspectContainer(containerId));
registerShutdownHook();
waitForPostgresToStart();
}
示例3: init
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
@Override
public void init() throws Exception {
Assume.assumeTrue(DockerTestUtils.isDockerAvailable());
this.creds = new DockerRegistryCredentials(
"127.0.0.1:5000",
"",
"",
"testing"
);
DockerClient client = DefaultDockerClient.fromEnv().build();
logger.info("Downloading registry image");
client.pull("registry:2");
final Map<String, List<PortBinding>> ports = singletonMap(
"5000/tcp", Collections.singletonList(PortBinding.of("0.0.0.0", 5000)));
final HostConfig hostConfig = HostConfig.builder().portBindings(ports)
.build();
logger.info("Creating Local Registry Container");
ContainerConfig config = ContainerConfig.builder()
.hostConfig(hostConfig)
.image("registry:2").build();
String id = client.createContainer(config).id();
logger.info("Registry container id: {}", id);
logger.info("Starting registry container");
client.startContainer(id);
this.registryid = id;
}
示例4: createContainer
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
public String createContainer(String image, Path volume) throws DockerException, InterruptedException {
ContainerConfig containerConfig = ContainerConfig.builder()
.image(image)
.workingDir("/sandbox")
.hostConfig(
HostConfig.builder().binds(HostConfig.Bind.builder().from(volume.toString()).to("/sandbox").build()).build()
).cmd("sh", "-c", "while :; do sleep 1; done")
.build();
return createContainer(containerConfig);
}
示例5: prepareContainer
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
/**
* create container running configuration from running task
*
* @param task
*
* @return
*/
private ContainerConfig prepareContainer(Task task) {
final String functionName = task.getName();
final String language = task.getLanguage();
final DockerConfig dockerConfig = config.getDockers().get(language);
final Map<String, String> labels = new HashMap<>();
labels.put(LABEL_DSHELL_FUNCTION, functionName);
final Path path = Paths.get(task.getArtifact().getPath()).getParent();
List<String> binds = new ArrayList<>();
if (task.getDind() == Boolean.TRUE) {
binds.add(String.format("%s:%s:rw", DOCKER_SOCK_FIEL, DOCKER_SOCK_FIEL));
}
if (StringUtils.isNotBlank(task.getVolumes())) {
binds.addAll(Arrays.asList(task.getVolumes().trim().split(",")));
}
binds.add(String.format("%s:%s:rw", path, Constants.SCRIPTS_DIRE));
final HostConfig hostConfig = HostConfig.builder()
.binds(binds)
.publishAllPorts(true)
.build();
return ContainerConfig.builder()
.image(dockerConfig.getImage())
.labels(labels)
.hostConfig(hostConfig)
.build();
}
示例6: create
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
public static DockerContainer create(CreateAgentRequest request, PluginSettings settings, DockerClient docker) throws InterruptedException, DockerException, IOException {
String containerName = UUID.randomUUID().toString();
HashMap<String, String> labels = labelsFrom(request);
String imageName = image(request.properties());
List<String> env = environmentFrom(request, settings, containerName);
try {
docker.inspectImage(imageName);
} catch (ImageNotFoundException ex) {
LOG.info("Image " + imageName + " not found, attempting to download.");
docker.pull(imageName);
}
ContainerConfig.Builder containerConfigBuilder = ContainerConfig.builder();
if (StringUtils.isNotBlank(request.properties().get("Command"))) {
containerConfigBuilder.cmd(splitIntoLinesAndTrimSpaces(request.properties().get("Command")).toArray(new String[]{}));
}
final String hostConfig = request.properties().get("Hosts");
ContainerConfig containerConfig = containerConfigBuilder
.image(imageName)
.labels(labels)
.env(env)
.hostConfig(HostConfig.builder().extraHosts(new Hosts(hostConfig)).build())
.build();
ContainerCreation container = docker.createContainer(containerConfig, containerName);
String id = container.id();
ContainerInfo containerInfo = docker.inspectContainer(id);
LOG.debug("Created container " + containerName);
docker.startContainer(containerName);
LOG.debug("container " + containerName + " started");
return new DockerContainer(containerName, containerInfo.created(), request.properties(), request.environment());
}
示例7: addLxcParameter
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
@Override
public RxDeployment addLxcParameter(String key, String value) {
LinkedList<HostConfig.LxcConfParameter> list = new LinkedList<>();
list.add(new HostConfig.LxcConfParameter(key, value));
if (this.hostConfig.lxcConf()!= null) {
list.addAll(this.hostConfig.lxcConf());
}
this.hostConfig.lxcConf(list);
return this;
}
示例8: before
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
@Override
protected void before() throws Throwable {
// Create a client based on DOCKER_HOST and DOCKER_CERT_PATH env vars
docker = DefaultDockerClient.fromEnv().build();
hostName = docker.getHost();
docker.pull(POSTGRES_9_2_IMAGE);
// Bind container ports to host ports
localPort = NetworkUtils.findAvailablePort();
final HostConfig hostConfig = HostConfig.builder()
.portBindings(createPortBinding(POSTGRESQL_PORT, localPort))
.build();
this.container = docker.createContainer(ContainerConfig.builder()
.image(POSTGRES_9_2_IMAGE)
.hostConfig(hostConfig)
.exposedPorts(String.valueOf(POSTGRESQL_PORT))
.build());
docker.startContainer(container.id());
waitForDatabase(RETRIES);
createDatabase();
Flyway flyway = new Flyway();
flyway.setSqlMigrationPrefix("v");
flyway.setSqlMigrationSeparator("-");
flyway.setDataSource(getDataSource(databaseName));
flyway.migrate();
for (String script : scripts) {
executeScript(script);
}
}
示例9: buildContainerConfig
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
@Override
public ContainerConfig buildContainerConfig(ContainerRequest request, String ownerUsername,
UriComponentsBuilder requestUri)
throws MccyException, DockerException, InterruptedException {
final int requestedPort = request.getPort();
PortBinding portBinding = PortBinding.of("",
requestedPort != 0 ? String.valueOf(requestedPort) : "");
Map<String, List<PortBinding>> portBindings =
singletonMap(MccyConstants.SERVER_CONTAINER_PORT, singletonList(portBinding));
final HostConfig.Builder hostConfig = HostConfig.builder()
.portBindings(portBindings);
final ArrayList<String> env = new ArrayList<>();
fillAssetsLinkage(hostConfig, env, request, requestUri);
return ContainerConfig.builder()
.attachStdin(true)
.tty(true)
.exposedPorts(MccyConstants.SERVER_CONTAINER_PORT)
.env(fillEnv(env, request))
.image(mccySettings.getImage())
.hostConfig(hostConfig.build())
.labels(buildLabels(request, ownerUsername))
.build();
}
示例10: startContainer
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
private void startContainer() throws Exception {
final DockerClient dockerClient = DefaultDockerClient.fromEnv().build();
logger.info("Pulling image spotify/kafka");
dockerClient.pull("spotify/kafka");
final String[] ports = {"2181", "9092"};
List<String> env = new ArrayList<>();
env.add("ADVERTISED_PORT=9092");
env.add("ADVERTISED_HOST=192.168.59.103");
final Map<String, List<PortBinding>> portBindings = new HashMap<>();
for (String port : ports) {
List<PortBinding> hostPorts = new ArrayList<>();
hostPorts.add(PortBinding.of("0.0.0.0", port));
portBindings.put(port, hostPorts);
}
final HostConfig hostConfig = HostConfig.builder().portBindings(portBindings).build();
final ContainerConfig containerConfig = ContainerConfig.builder()
.hostConfig(hostConfig)
.image("spotify/kafka")
.exposedPorts(ports)
.env(env)
.build();
final ContainerCreation creation = dockerClient.createContainer(containerConfig);
containerId = creation.id();
logger.info("Starting container");
// Start container
dockerClient.startContainer(containerId);
}
示例11: updateContainer
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
@Override
public ContainerUpdate updateContainer(String string, HostConfig hc) {
throw new IllegalStateException(DISCONNECTED);
}
示例12: SpotifyOptions
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
public SpotifyOptions(SpotifyRxDocker docker) {
this.containerConfig = ContainerConfig.builder();
this.hostConfig = HostConfig.builder();
this.docker = docker;
}
示例13: RestartPolicy
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
public RestartPolicy(HostConfig.RestartPolicy restartPolicy) {
this.restartPolicy = restartPolicy;
}
示例14: getRestartPolicy
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
public HostConfig.RestartPolicy getRestartPolicy() {
return restartPolicy;
}
示例15: unlessStopped
import com.spotify.docker.client.messages.HostConfig; //导入依赖的package包/类
/**
* 'unlessStopped' restart policy.
*/
public static RestartPolicy unlessStopped() {
return new RestartPolicy(HostConfig.RestartPolicy.unlessStopped());
}