4848
4949import static com .github .dockerjava .api .model .Capability .MKNOD ;
5050import static com .github .dockerjava .api .model .Capability .NET_ADMIN ;
51+ import static com .github .dockerjava .api .model .HostConfig .newHostConfig ;
5152import static com .github .dockerjava .cmd .CmdIT .FactoryType .JERSEY ;
5253import static com .github .dockerjava .core .RemoteApiVersion .VERSION_1_23 ;
5354import static com .github .dockerjava .core .RemoteApiVersion .VERSION_1_24 ;
@@ -160,7 +161,8 @@ public void createContainerWithVolumesFrom() throws DockerException {
160161 CreateContainerResponse container1 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
161162 .withCmd ("sleep" , "9999" )
162163 .withName (container1Name )
163- .withBinds (bind1 , bind2 )
164+ .withHostConfig (newHostConfig ()
165+ .withBinds (bind1 , bind2 ))
164166 .exec ();
165167
166168 LOG .info ("Created container1 {}" , container1 .toString ());
@@ -175,7 +177,8 @@ public void createContainerWithVolumesFrom() throws DockerException {
175177 // create a second container with volumes from first container
176178 CreateContainerResponse container2 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
177179 .withCmd ("sleep" , "9999" )
178- .withVolumesFrom (new VolumesFrom (container1Name ))
180+ .withHostConfig (newHostConfig ()
181+ .withVolumesFrom (new VolumesFrom (container1Name )))
179182 .exec ();
180183
181184 LOG .info ("Created container2 {}" , container2 .toString ());
@@ -285,7 +288,10 @@ public void createContainerWithLink() throws DockerException {
285288 assertThat (inspectContainerResponse1 .getState ().getRunning (), is (true ));
286289
287290 CreateContainerResponse container2 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withName (containerName2 )
288- .withCmd ("env" ).withLinks (new Link (containerName1 , "container1Link" )).exec ();
291+ .withCmd ("env" )
292+ .withHostConfig (newHostConfig ()
293+ .withLinks (new Link (containerName1 , "container1Link" )))
294+ .exec ();
289295 LOG .info ("Created container {}" , container2 .toString ());
290296 assertThat (container2 .getId (), not (isEmptyString ()));
291297
@@ -299,7 +305,8 @@ public void createContainerWithLink() throws DockerException {
299305 public void createContainerWithMemorySwappiness () throws DockerException {
300306 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
301307 .withCmd ("sleep" , "9999" )
302- .withMemorySwappiness (42 )
308+ .withHostConfig (newHostConfig ()
309+ .withMemorySwappiness (42 ))
303310 .exec ();
304311 assertThat (container .getId (), not (isEmptyString ()));
305312 LOG .info ("Created container {}" , container .toString ());
@@ -328,8 +335,9 @@ public void createContainerWithLinkInCustomNetwork() throws DockerException {
328335 assertNotNull (createNetworkResponse .getId ());
329336
330337 CreateContainerResponse container1 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
331- .withNetworkMode (networkName )
332338 .withCmd ("sleep" , "9999" )
339+ .withHostConfig (newHostConfig ()
340+ .withNetworkMode (networkName ))
333341 .withName (containerName1 )
334342 .exec ();
335343
@@ -343,10 +351,12 @@ public void createContainerWithLinkInCustomNetwork() throws DockerException {
343351 assertThat (inspectContainerResponse1 .getState ().getRunning (), is (true ));
344352
345353 CreateContainerResponse container2 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
346- .withNetworkMode (networkName )
354+ .withHostConfig (newHostConfig ()
355+ .withNetworkMode (networkName )
356+ .withLinks (new Link (containerName1 , containerName1 + "Link" ))
357+ )
347358 .withName (containerName2 )
348359 .withCmd ("env" )
349- .withLinks (new Link (containerName1 , containerName1 + "Link" ))
350360 .exec ();
351361
352362 LOG .info ("Created container {}" , container2 .toString ());
@@ -377,10 +387,11 @@ public void createContainerWithCustomIp() throws DockerException {
377387 assertNotNull (createNetworkResponse .getId ());
378388
379389 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
380- .withNetworkMode (networkName )
381390 .withCmd ("sleep" , "9999" )
391+ .withHostConfig (newHostConfig ()
392+ .withNetworkMode (networkName ))
382393 .withName (containerName1 )
383- .withIpv4Address (subnetPrefix +".100" )
394+ .withIpv4Address (subnetPrefix + ".100" )
384395 .exec ();
385396
386397 assertThat (container .getId (), not (isEmptyString ()));
@@ -410,8 +421,9 @@ public void createContainerWithAlias() throws DockerException {
410421 assertNotNull (createNetworkResponse .getId ());
411422
412423 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
413- .withNetworkMode (networkName )
414424 .withCmd ("sleep" , "9999" )
425+ .withHostConfig (newHostConfig ()
426+ .withNetworkMode (networkName ))
415427 .withName (containerName1 )
416428 .withAliases ("server" + dockerRule .getKind ())
417429 .exec ();
@@ -430,8 +442,11 @@ public void createContainerWithAlias() throws DockerException {
430442 @ Test
431443 public void createContainerWithCapAddAndCapDrop () throws DockerException {
432444
433- CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCapAdd (NET_ADMIN )
434- .withCapDrop (MKNOD ).exec ();
445+ CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
446+ .withHostConfig (newHostConfig ()
447+ .withCapAdd (NET_ADMIN )
448+ .withCapDrop (MKNOD ))
449+ .exec ();
435450
436451 LOG .info ("Created container {}" , container .toString ());
437452
@@ -451,7 +466,9 @@ public void createContainerWithDns() throws DockerException {
451466 String anotherDnsServer = "8.8.4.4" ;
452467
453468 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCmd ("true" )
454- .withDns (aDnsServer , anotherDnsServer ).exec ();
469+ .withHostConfig (newHostConfig ()
470+ .withDns (aDnsServer , anotherDnsServer ))
471+ .exec ();
455472
456473 LOG .info ("Created container {}" , container .toString ());
457474
@@ -487,7 +504,9 @@ public void createContainerWithExtraHosts() throws DockerException {
487504
488505 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
489506 .withName ("containerextrahosts" + dockerRule .getKind ())
490- .withExtraHosts (extraHosts ).exec ();
507+ .withHostConfig (newHostConfig ()
508+ .withExtraHosts (extraHosts ))
509+ .exec ();
491510
492511 LOG .info ("Created container {}" , container .toString ());
493512
@@ -503,7 +522,8 @@ public void createContainerWithExtraHosts() throws DockerException {
503522 public void createContainerWithDevices () throws DockerException {
504523
505524 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCmd ("sleep" , "9999" )
506- .withDevices (new Device ("rwm" , "/dev/nulo" , "/dev/zero" )).exec ();
525+ .withHostConfig (newHostConfig ()
526+ .withDevices (new Device ("rwm" , "/dev/nulo" , "/dev/zero" ))).exec ();
507527
508528 LOG .info ("Created container {}" , container .toString ());
509529
@@ -517,7 +537,7 @@ public void createContainerWithDevices() throws DockerException {
517537
518538 @ Test
519539 public void createContainerWithPortBindings () throws DockerException {
520- int baseport = getFactoryType () == FactoryType .JERSEY ? 11000 : 12000 ;
540+ int baseport = getFactoryType () == FactoryType .JERSEY ? 11000 : 12000 ;
521541
522542 ExposedPort tcp22 = ExposedPort .tcp (22 );
523543 ExposedPort tcp23 = ExposedPort .tcp (23 );
@@ -528,7 +548,8 @@ public void createContainerWithPortBindings() throws DockerException {
528548 portBindings .bind (tcp23 , Binding .bindPort (baseport + 24 ));
529549
530550 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCmd ("true" )
531- .withExposedPorts (tcp22 , tcp23 ).withPortBindings (portBindings ).exec ();
551+ .withExposedPorts (tcp22 , tcp23 ).withHostConfig (newHostConfig ()
552+ .withPortBindings (portBindings )).exec ();
532553
533554 LOG .info ("Created container {}" , container .toString ());
534555
@@ -581,7 +602,8 @@ public void createContainerWithLinking() throws DockerException {
581602
582603 CreateContainerResponse container2 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCmd ("sleep" , "9999" )
583604 .withName (containerName2 )
584- .withLinks (new Link (containerName1 , containerName1 + "Link" )).exec ();
605+ .withHostConfig (newHostConfig ()
606+ .withLinks (new Link (containerName1 , containerName1 + "Link" ))).exec ();
585607
586608 LOG .info ("Created container2 {}" , container2 .toString ());
587609 assertThat (container2 .getId (), not (isEmptyString ()));
@@ -608,7 +630,8 @@ public void createContainerWithRestartPolicy() throws DockerException {
608630 RestartPolicy restartPolicy = RestartPolicy .onFailureRestart (5 );
609631
610632 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCmd ("sleep" , "9999" )
611- .withRestartPolicy (restartPolicy ).exec ();
633+ .withHostConfig (newHostConfig ()
634+ .withRestartPolicy (restartPolicy )).exec ();
612635
613636 LOG .info ("Created container {}" , container .toString ());
614637
@@ -623,7 +646,8 @@ public void createContainerWithRestartPolicy() throws DockerException {
623646 public void createContainerWithPidMode () throws DockerException {
624647
625648 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCmd ("true" )
626- .withPidMode ("host" ).exec ();
649+ .withHostConfig (newHostConfig ()
650+ .withPidMode ("host" )).exec ();
627651
628652 LOG .info ("Created container {}" , container .toString ());
629653
@@ -644,7 +668,8 @@ public void createContainerWithPidMode() throws DockerException {
644668 public void createContainerWithNetworkMode () throws DockerException {
645669
646670 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCmd ("true" )
647- .withNetworkMode ("host" ).exec ();
671+ .withHostConfig (newHostConfig ()
672+ .withNetworkMode ("host" )).exec ();
648673
649674 LOG .info ("Created container {}" , container .toString ());
650675
@@ -677,7 +702,8 @@ public void createContainerWithULimits() throws DockerException {
677702
678703 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
679704 .withName (containerName )
680- .withUlimits (ulimits ).exec ();
705+ .withHostConfig (newHostConfig ()
706+ .withUlimits (ulimits )).exec ();
681707
682708 LOG .info ("Created container {}" , container .toString ());
683709
@@ -720,7 +746,10 @@ public void createContainerWithLabels() throws DockerException {
720746 public void createContainerWithLogConfig () throws DockerException {
721747
722748 LogConfig logConfig = new LogConfig (LogConfig .LoggingType .NONE , null );
723- CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withLogConfig (logConfig ).exec ();
749+ CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
750+ .withHostConfig (newHostConfig ()
751+ .withLogConfig (logConfig ))
752+ .exec ();
724753
725754 LOG .info ("Created container {}" , container .toString ());
726755
@@ -789,7 +818,8 @@ public void onNext(Frame item) {
789818 @ Test
790819 public void createContainerWithCgroupParent () throws DockerException {
791820 CreateContainerResponse container = dockerRule .getClient ().createContainerCmd ("busybox" )
792- .withCgroupParent ("/parent" ).exec ();
821+ .withHostConfig (newHostConfig ()
822+ .withCgroupParent ("/parent" )).exec ();
793823
794824 LOG .info ("Created container {}" , container .toString ());
795825
0 commit comments