use of com.github.dockerjava.api.model.Ports.Binding in project elastest-torm by elastest.
the class DockerComposeService method setup.
public void setup() throws IOException, InterruptedException {
// 1. Start docker-compose-ui container
dockerComposeUiContainerName = dockerService.generateContainerName(dockerComposeUiPrefix);
int dockerComposeBindPort = dockerService.findRandomOpenPort();
Binding bindNoVncPort = bindPort(dockerComposeBindPort);
ExposedPort exposedNoVncPort = tcp(dockerComposeUiPort);
String dockerComposeServiceUrl = "http://" + dockerService.getDockerServerIp() + ":" + dockerComposeBindPort;
log.debug("Starting docker-compose-ui container: {}", dockerComposeUiContainerName);
List<PortBinding> portBindings = asList(new PortBinding(bindNoVncPort, exposedNoVncPort));
Volume volume = new Volume(dockerDefaultSocket);
List<Volume> volumes = asList(volume);
List<Bind> binds = asList(new Bind(dockerDefaultSocket, volume));
DockerBuilder dockerBuilder = dockerBuilder(dockerComposeUiImageId, dockerComposeUiContainerName).portBindings(portBindings).volumes(volumes).binds(binds);
dockerService.startAndWaitContainer(dockerBuilder.build());
// 2. Create Retrofit object to call docker-compose-ui REST API
OkHttpClient okHttpClient = new OkHttpClient.Builder().readTimeout(dockerComposeTimeout, SECONDS).connectTimeout(dockerComposeTimeout, SECONDS).build();
Retrofit retrofit = new Retrofit.Builder().client(okHttpClient).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).addConverterFactory(GsonConverterFactory.create()).baseUrl(dockerComposeServiceUrl).build();
dockerComposeApi = retrofit.create(DockerComposeApi.class);
log.debug("docker-compose-ui up and running on URL: {}", dockerComposeServiceUrl);
// 3.Delete default example projects
dockerService.waitForHostIsReachable(dockerComposeServiceUrl);
String[] defaultProjects = { "env-demo", "hello-node", "node-redis", "volumes-demo", "volumes-relative-paths" };
removeProjects(defaultProjects);
}
use of com.github.dockerjava.api.model.Ports.Binding in project elastest-torm by elastest.
the class DockerUnitTest method testEmptyContainer.
@Test
@DisplayName("Try to start a container with invalid input")
void testEmptyContainer() {
assertThrows(Exception.class, () -> {
Binding bindPort = bindPort(0);
ExposedPort exposedPort = tcp(0);
List<PortBinding> portBindings = asList(new PortBinding(bindPort, exposedPort));
dockerService.startAndWaitContainer(dockerBuilder("", "").portBindings(portBindings).build());
});
}
use of com.github.dockerjava.api.model.Ports.Binding in project elastest-torm by elastest.
the class DockerIntegrationTest method testDocker.
@Test
@DisplayName("Ask for Chrome to Docker")
void testDocker() throws Exception {
// Test data (input)
String imageId = "selenium/standalone-chrome-debug:3.5.3";
log.debug("Starting Hub with image {}", imageId);
String containerName = dockerService.generateContainerName("hub-for-test-");
Binding bindPort = bindPort(dockerService.findRandomOpenPort());
ExposedPort exposedPort = tcp(4444);
Binding bindHubVncPort = bindPort(dockerService.findRandomOpenPort());
ExposedPort exposedHubVncPort = tcp(5900);
List<PortBinding> portBindings = asList(new PortBinding(bindPort, exposedPort), new PortBinding(bindHubVncPort, exposedHubVncPort));
DockerBuilder dockerBuilder = dockerBuilder(imageId, containerName).portBindings(portBindings);
dockerService.startAndWaitContainer(dockerBuilder.build());
// Assertions
assertTrue(dockerService.existsContainer(containerName));
// Tear down
log.debug("Stoping Hub");
dockerService.stopAndRemoveContainer(containerName);
}
Aggregations