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());
}
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));
}
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();
}
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;
}
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());
}
Aggregations