2323import de .rub .nds .tls .subject .HostInfo ;
2424import de .rub .nds .tls .subject .params .ParameterProfile ;
2525import de .rub .nds .tls .subject .properties .ImageProperties ;
26- import static java .lang .Thread .sleep ;
27- import java .util .logging .Level ;
28- import java .util .logging .Logger ;
2926
3027public class DockerTlsServerInstance extends DockerTlsInstance {
3128
@@ -62,10 +59,10 @@ protected CreateContainerCmd prepareCreateContainerCmd(CreateContainerCmd cmd) {
6259 } else {
6360 host = hostInfo .getHostname ();
6461 }
65- return super .prepareCreateContainerCmd (cmd ). withCmd ( parameterProfile . toParameters ( host ,
66- imageProperties . getInternalPort ( ), imageProperties , additionalParameters , parallelize , insecureConnection ))
67- . withExposedPorts (
68- new ExposedPort (imageProperties . getInternalPort (), hostInfo .getType ().toInternetProtocol ()));
62+ return super .prepareCreateContainerCmd (cmd )
63+ . withCmd ( parameterProfile . toParameters ( host , hostInfo . getPort ( ), imageProperties , additionalParameters ,
64+ parallelize , insecureConnection ))
65+ . withExposedPorts ( new ExposedPort (hostInfo . getPort (), hostInfo .getType ().toInternetProtocol ()));
6966 }
7067
7168 @ Override
@@ -78,7 +75,20 @@ public void start() {
7875 * Update port to match actually exposed port.
7976 */
8077 public void updateInstancePort () {
81- port = imageProperties .getInternalPort ();
78+ InspectContainerResponse containerInfo = DOCKER .inspectContainerCmd (getId ()).exec ();
79+ if (containerInfo == null ) {
80+ throw new IllegalStateException ("Could not find container with ID:" + getId ());
81+ }
82+ NetworkSettings networkSettings = containerInfo .getNetworkSettings ();
83+ if (networkSettings == null ) {
84+ throw new IllegalStateException (
85+ "Cannot retrieve InstacePort, Network not properly configured for container with ID:" + getId ());
86+ }
87+ Binding [] binding = networkSettings .getPorts ().getBindings ().values ().iterator ().next ();
88+ if (binding != null ) {
89+ // only update if port mapping was necessary
90+ port = Integer .valueOf (binding [0 ].getHostPortSpec ());
91+ }
8292 }
8393
8494 public int getPort () {
0 commit comments