use of com.github.dockerjava.api.model.Ports 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.Ports 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.Ports in project testcontainers-java by testcontainers.
the class ContainerState method getPortBindings.
/**
* @return the port bindings
*/
default List<String> getPortBindings() {
List<String> portBindings = new ArrayList<>();
final Ports hostPortBindings = this.getContainerInfo().getHostConfig().getPortBindings();
for (Map.Entry<ExposedPort, Ports.Binding[]> binding : hostPortBindings.getBindings().entrySet()) {
for (Ports.Binding portBinding : binding.getValue()) {
portBindings.add(String.format("%s:%s", portBinding.toString(), binding.getKey()));
}
}
return portBindings;
}
use of com.github.dockerjava.api.model.Ports in project elastest-torm by elastest.
the class DockerService2 method bindingPort.
public SocatBindedPort bindingPort(String containerIp, String port, String networkName) throws Exception {
DockerClient dockerClient = this.getDockerClient();
int listenPort = 37000;
String bindedPort = null;
try {
listenPort = utilTools.findRandomOpenPort();
List<String> envVariables = new ArrayList<>();
envVariables.add("LISTEN_PORT=" + listenPort);
envVariables.add("FORWARD_PORT=" + port);
envVariables.add("TARGET_SERVICE_IP=" + containerIp);
Ports portBindings = new Ports();
ExposedPort exposedListenPort = ExposedPort.tcp(listenPort);
portBindings.bind(exposedListenPort, Ports.Binding.bindPort(listenPort));
bindedPort = this.runDockerContainer(dockerClient, etSocatImage, envVariables, "container" + listenPort, networkName, portBindings, listenPort);
} catch (Exception e) {
e.printStackTrace();
throw new Exception(e.getMessage());
}
SocatBindedPort bindedPortObj = new SocatBindedPort(Integer.toString(listenPort), bindedPort);
return bindedPortObj;
}
Aggregations