use of com.github.dockerjava.api.model.ExposedPort in project camel by apache.
the class CreateContainerCmdHeaderTest method createContainerHeaderTest.
@Test
public void createContainerHeaderTest() {
String image = "busybox";
ExposedPort exposedPort = ExposedPort.tcp(22);
boolean tty = true;
String name = "cameldocker";
String workingDir = "/opt";
boolean disableNetwork = false;
String domainName = "apache.org";
String hostname = "dockerjava";
String user = "docker";
boolean stdInOpen = false;
boolean stdInOnce = false;
boolean attachStdErr = true;
boolean attachStdOut = true;
boolean attachStdIn = false;
Long memoryLimit = 2048L;
Long swapMemory = 512L;
Integer cpuShares = 512;
Volume volumes = new Volume("/example");
VolumesFrom volumesFromContainer = new VolumesFrom("/etc");
String env = "FOO=bar";
String cmd = "whoami";
HostConfig hostConfig = new HostConfig();
Capability capAdd = Capability.NET_BROADCAST;
Capability capDrop = Capability.BLOCK_SUSPEND;
String[] entrypoint = new String[] { "sleep", "9999" };
String portSpecs = "80";
String dns = "8.8.8.8";
Map<String, Object> headers = getDefaultParameters();
headers.put(DockerConstants.DOCKER_IMAGE, image);
headers.put(DockerConstants.DOCKER_EXPOSED_PORTS, exposedPort);
headers.put(DockerConstants.DOCKER_TTY, tty);
headers.put(DockerConstants.DOCKER_NAME, name);
headers.put(DockerConstants.DOCKER_WORKING_DIR, workingDir);
headers.put(DockerConstants.DOCKER_DISABLE_NETWORK, disableNetwork);
headers.put(DockerConstants.DOCKER_HOSTNAME, hostname);
headers.put(DockerConstants.DOCKER_USER, user);
headers.put(DockerConstants.DOCKER_STD_IN_OPEN, stdInOpen);
headers.put(DockerConstants.DOCKER_STD_IN_ONCE, stdInOnce);
headers.put(DockerConstants.DOCKER_ATTACH_STD_IN, attachStdIn);
headers.put(DockerConstants.DOCKER_ATTACH_STD_ERR, attachStdErr);
headers.put(DockerConstants.DOCKER_ATTACH_STD_OUT, attachStdOut);
headers.put(DockerConstants.DOCKER_MEMORY_LIMIT, memoryLimit);
headers.put(DockerConstants.DOCKER_MEMORY_SWAP, swapMemory);
headers.put(DockerConstants.DOCKER_CPU_SHARES, cpuShares);
headers.put(DockerConstants.DOCKER_VOLUMES, volumes);
headers.put(DockerConstants.DOCKER_VOLUMES_FROM, volumesFromContainer);
headers.put(DockerConstants.DOCKER_ENV, env);
headers.put(DockerConstants.DOCKER_CMD, cmd);
headers.put(DockerConstants.DOCKER_HOST_CONFIG, hostConfig);
headers.put(DockerConstants.DOCKER_CAP_ADD, capAdd);
headers.put(DockerConstants.DOCKER_CAP_DROP, capDrop);
headers.put(DockerConstants.DOCKER_ENTRYPOINT, entrypoint);
headers.put(DockerConstants.DOCKER_PORT_SPECS, portSpecs);
headers.put(DockerConstants.DOCKER_DNS, dns);
headers.put(DockerConstants.DOCKER_DOMAIN_NAME, domainName);
template.sendBodyAndHeaders("direct:in", "", headers);
Mockito.verify(dockerClient, Mockito.times(1)).createContainerCmd(image);
Mockito.verify(mockObject, Mockito.times(1)).withExposedPorts(Matchers.eq(exposedPort));
Mockito.verify(mockObject, Mockito.times(1)).withTty(Matchers.eq(tty));
Mockito.verify(mockObject, Mockito.times(1)).withName(Matchers.eq(name));
Mockito.verify(mockObject, Mockito.times(1)).withWorkingDir(workingDir);
Mockito.verify(mockObject, Mockito.times(1)).withNetworkDisabled(disableNetwork);
Mockito.verify(mockObject, Mockito.times(1)).withHostName(hostname);
Mockito.verify(mockObject, Mockito.times(1)).withUser(user);
Mockito.verify(mockObject, Mockito.times(1)).withStdinOpen(stdInOpen);
Mockito.verify(mockObject, Mockito.times(1)).withStdInOnce(stdInOnce);
Mockito.verify(mockObject, Mockito.times(1)).withAttachStderr(attachStdErr);
Mockito.verify(mockObject, Mockito.times(1)).withAttachStdin(attachStdIn);
Mockito.verify(mockObject, Mockito.times(1)).withAttachStdout(attachStdOut);
Mockito.verify(mockObject, Mockito.times(1)).withMemory(memoryLimit);
Mockito.verify(mockObject, Mockito.times(1)).withMemorySwap(swapMemory);
Mockito.verify(mockObject, Mockito.times(1)).withCpuShares(cpuShares);
Mockito.verify(mockObject, Mockito.times(1)).withVolumes(volumes);
Mockito.verify(mockObject, Mockito.times(1)).withVolumesFrom(volumesFromContainer);
Mockito.verify(mockObject, Mockito.times(1)).withEnv(env);
Mockito.verify(mockObject, Mockito.times(1)).withCmd(cmd);
Mockito.verify(mockObject, Mockito.times(1)).withHostConfig(hostConfig);
Mockito.verify(mockObject, Mockito.times(1)).withCapAdd(capAdd);
Mockito.verify(mockObject, Mockito.times(1)).withCapDrop(capDrop);
Mockito.verify(mockObject, Mockito.times(1)).withEntrypoint(entrypoint);
Mockito.verify(mockObject, Mockito.times(1)).withPortSpecs(portSpecs);
Mockito.verify(mockObject, Mockito.times(1)).withDns(dns);
Mockito.verify(mockObject, Mockito.times(1)).withDomainName(domainName);
}
use of com.github.dockerjava.api.model.ExposedPort in project dockerunit by qzagarese.
the class ConsulDescriptor method setup.
@ContainerBuilder
public CreateContainerCmd setup(CreateContainerCmd cmd) {
List<ExposedPort> ports = new ArrayList<>(Arrays.asList(cmd.getExposedPorts()));
ExposedPort dnsPort = ExposedPort.udp(CONSUL_DNS_PORT);
ports.add(dnsPort);
ExposedPort consulPort = ExposedPort.tcp(CONSUL_PORT);
ports.add(consulPort);
Ports bindings = cmd.getPortBindings();
if (bindings == null) {
bindings = new Ports();
}
bindings.bind(dnsPort, Binding.bindPort(8600));
bindings.bind(consulPort, Binding.bindPort(8500));
return cmd.withExposedPorts(ports).withPortBindings(bindings).withCmd("agent", "-dev", "-client=0.0.0.0", "-enable-script-checks");
}
use of com.github.dockerjava.api.model.ExposedPort in project dockerunit by qzagarese.
the class PortBindingExtensionInterpreter method build.
@Override
public CreateContainerCmd build(TestDescriptor td, CreateContainerCmd cmd, PortBinding pb) {
List<ExposedPort> ports = new ArrayList<>(Arrays.asList(cmd.getExposedPorts()));
ExposedPort containerPort = pb.protocol().equals(Protocol.TCP) ? ExposedPort.tcp(pb.exposedPort()) : ExposedPort.udp(pb.exposedPort());
ports.add(containerPort);
Ports bindings = cmd.getPortBindings();
if (bindings == null) {
bindings = new Ports();
}
bindings.bind(containerPort, pb.hostIp().isEmpty() ? Binding.bindPort(pb.hostPort()) : Binding.bindIpAndPort(pb.hostIp(), pb.hostPort()));
return cmd.withExposedPorts(ports).withPortBindings(bindings);
}
use of com.github.dockerjava.api.model.ExposedPort 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.ExposedPort 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());
});
}
Aggregations