Search in sources :

Example 31 with HostConfig

use of com.spotify.docker.client.messages.HostConfig in project helios by spotify.

the class SyslogRedirectingContainerDecoratorTest method testWithDockerVersionPre1_9.

@Test
public void testWithDockerVersionPre1_9() {
    final Optional<String> dockerVersion = Optional.of("1.6.0");
    final SyslogRedirectingContainerDecorator decorator = new SyslogRedirectingContainerDecorator(SYSLOG_HOST_PORT);
    final HostConfig.Builder hostBuilder = HostConfig.builder();
    decorator.decorateHostConfig(JOB, dockerVersion, hostBuilder);
    final ContainerConfig.Builder containerBuilder = ContainerConfig.builder();
    decorator.decorateContainerConfig(JOB, imageInfo, dockerVersion, containerBuilder);
    final ContainerConfig containerConfig = containerBuilder.build();
    assertThat(containerConfig.entrypoint(), hasItem("/helios/syslog-redirector"));
    final HostConfig hostConfig = hostBuilder.build();
    assertNull(hostConfig.logConfig());
    assertFalse(hostConfig.binds().isEmpty());
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) HostConfig(com.spotify.docker.client.messages.HostConfig) Test(org.junit.Test)

Example 32 with HostConfig

use of com.spotify.docker.client.messages.HostConfig in project helios by spotify.

the class TaskConfigTest method testHostConfig.

@Test
public void testHostConfig() throws Exception {
    final TaskConfig taskConfig = TaskConfig.builder().namespace("test").host(HOST).job(JOB).build();
    final HostConfig hostConfig = taskConfig.hostConfig(Optional.absent());
    assertThat(ImmutableSet.copyOf(hostConfig.capAdd()), equalTo(CAP_ADDS));
    assertThat(ImmutableSet.copyOf(hostConfig.capDrop()), equalTo(CAP_DROPS));
}
Also used : HostConfig(com.spotify.docker.client.messages.HostConfig) Test(org.junit.Test)

Example 33 with HostConfig

use of com.spotify.docker.client.messages.HostConfig in project hale by halestudio.

the class HaleDockerClient method startContainer.

/**
 * start a container. Container can be started in the privileged mode if the
 * 'isPrivileged' key in the configuration is set as true.
 *
 * @throws DockerException docker exception
 * @throws InterruptedException interrupted exception
 */
public void startContainer() throws DockerException, InterruptedException {
    try {
        dc.inspectImage(containerConf.image());
    } catch (ImageNotFoundException e) {
        // pull image if it is not present
        LOGGER.info(MessageFormat.format("Docker image not found, attempting to pull image {0}...", containerConf.image()));
        dc.pull(containerConf.image());
    }
    // TODO also add a setting to pull the image always?
    LOGGER.info(MessageFormat.format("Preparing container for image {0}...", containerConf.image()));
    creation = dc.createContainer(containerConf);
    containerId = creation.id();
    LOGGER.info(MessageFormat.format("Created container with ID {0}, now starting...", containerId));
    final HostConfig hostConfig;
    if (getHostName() == null) {
        // don't publish ports (probably unix socket connection)
        hostConfig = HostConfig.builder().publishAllPorts(false).privileged(dbc.isPrivileged()).build();
    } else {
        // XXX publishing all ports can be very bad if the host is
        // accessible externally
        hostConfig = HostConfig.builder().publishAllPorts(dbc.isExposeAllPorts()).privileged(dbc.isPrivileged()).build();
    }
    dc.startContainer(containerId, hostConfig);
    final ContainerInfo info = dc.inspectContainer(containerId);
    portMapper = info.networkSettings().ports();
    containerIp = info.networkSettings().ipAddress();
}
Also used : HostConfig(com.spotify.docker.client.messages.HostConfig) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) ImageNotFoundException(com.spotify.docker.client.ImageNotFoundException)

Example 34 with HostConfig

use of com.spotify.docker.client.messages.HostConfig in project TOSCAna by StuPro-TOSCAna.

the class PushingImageBuilderIT method init.

@Override
public void init() throws Exception {
    Assume.assumeTrue(DockerTestUtils.isDockerAvailable());
    this.credentials = 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;
}
Also used : DockerRegistryCredentials(org.opentosca.toscana.plugins.kubernetes.docker.util.DockerRegistryCredentials) ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) HostConfig(com.spotify.docker.client.messages.HostConfig) List(java.util.List)

Example 35 with HostConfig

use of com.spotify.docker.client.messages.HostConfig in project TOSCAna by StuPro-TOSCAna.

the class KubernetesPushingGopherIT method onSuccess.

@Override
protected void onSuccess(File outputDir) throws Exception {
    DockerClient client = DefaultDockerClient.fromEnv().build();
    client.pull(getExpectedTag());
    int containerPort = TestUtil.getRandomOpenPort();
    Map<String, List<PortBinding>> ports = singletonMap("8080/tcp", Collections.singletonList(PortBinding.of("0.0.0.0", containerPort)));
    HostConfig hostConfig = HostConfig.builder().portBindings(ports).build();
    ContainerConfig config = ContainerConfig.builder().hostConfig(hostConfig).image(getExpectedTag()).build();
    String id = client.createContainer(config).id();
    this.runningContainers.add(id);
    client.startContainer(id);
    Thread.sleep(5000);
    OkHttpClient httpClient = new OkHttpClient();
    Request request = new Request.Builder().url(String.format("http://127.0.0.1:%d/", containerPort)).get().build();
    Response response = httpClient.newCall(request).execute();
    Assert.assertEquals(200, response.code());
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) HostConfig(com.spotify.docker.client.messages.HostConfig) Request(okhttp3.Request) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

HostConfig (com.spotify.docker.client.messages.HostConfig)53 ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)45 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)30 Test (org.junit.Test)29 Matchers.containsString (org.hamcrest.Matchers.containsString)22 Long.toHexString (java.lang.Long.toHexString)19 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)19 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)16 DockerClient (com.spotify.docker.client.DockerClient)12 List (java.util.List)11 DockerException (com.spotify.docker.client.exceptions.DockerException)8 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)6 LogStream (com.spotify.docker.client.LogStream)4 ContainerMount (com.spotify.docker.client.messages.ContainerMount)4 PortBinding (com.spotify.docker.client.messages.PortBinding)4 IOException (java.io.IOException)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ImmutableList (com.google.common.collect.ImmutableList)3