48
48
49
49
import static com .github .dockerjava .api .model .Capability .MKNOD ;
50
50
import static com .github .dockerjava .api .model .Capability .NET_ADMIN ;
51
+ import static com .github .dockerjava .api .model .HostConfig .newHostConfig ;
51
52
import static com .github .dockerjava .cmd .CmdIT .FactoryType .JERSEY ;
52
53
import static com .github .dockerjava .core .RemoteApiVersion .VERSION_1_23 ;
53
54
import static com .github .dockerjava .core .RemoteApiVersion .VERSION_1_24 ;
@@ -160,7 +161,8 @@ public void createContainerWithVolumesFrom() throws DockerException {
160
161
CreateContainerResponse container1 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
161
162
.withCmd ("sleep" , "9999" )
162
163
.withName (container1Name )
163
- .withBinds (bind1 , bind2 )
164
+ .withHostConfig (newHostConfig ()
165
+ .withBinds (bind1 , bind2 ))
164
166
.exec ();
165
167
166
168
LOG .info ("Created container1 {}" , container1 .toString ());
@@ -175,7 +177,8 @@ public void createContainerWithVolumesFrom() throws DockerException {
175
177
// create a second container with volumes from first container
176
178
CreateContainerResponse container2 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
177
179
.withCmd ("sleep" , "9999" )
178
- .withVolumesFrom (new VolumesFrom (container1Name ))
180
+ .withHostConfig (newHostConfig ()
181
+ .withVolumesFrom (new VolumesFrom (container1Name )))
179
182
.exec ();
180
183
181
184
LOG .info ("Created container2 {}" , container2 .toString ());
@@ -285,7 +288,10 @@ public void createContainerWithLink() throws DockerException {
285
288
assertThat (inspectContainerResponse1 .getState ().getRunning (), is (true ));
286
289
287
290
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 ();
289
295
LOG .info ("Created container {}" , container2 .toString ());
290
296
assertThat (container2 .getId (), not (isEmptyString ()));
291
297
@@ -299,7 +305,8 @@ public void createContainerWithLink() throws DockerException {
299
305
public void createContainerWithMemorySwappiness () throws DockerException {
300
306
CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
301
307
.withCmd ("sleep" , "9999" )
302
- .withMemorySwappiness (42 )
308
+ .withHostConfig (newHostConfig ()
309
+ .withMemorySwappiness (42 ))
303
310
.exec ();
304
311
assertThat (container .getId (), not (isEmptyString ()));
305
312
LOG .info ("Created container {}" , container .toString ());
@@ -328,8 +335,9 @@ public void createContainerWithLinkInCustomNetwork() throws DockerException {
328
335
assertNotNull (createNetworkResponse .getId ());
329
336
330
337
CreateContainerResponse container1 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
331
- .withNetworkMode (networkName )
332
338
.withCmd ("sleep" , "9999" )
339
+ .withHostConfig (newHostConfig ()
340
+ .withNetworkMode (networkName ))
333
341
.withName (containerName1 )
334
342
.exec ();
335
343
@@ -343,10 +351,12 @@ public void createContainerWithLinkInCustomNetwork() throws DockerException {
343
351
assertThat (inspectContainerResponse1 .getState ().getRunning (), is (true ));
344
352
345
353
CreateContainerResponse container2 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
346
- .withNetworkMode (networkName )
354
+ .withHostConfig (newHostConfig ()
355
+ .withNetworkMode (networkName )
356
+ .withLinks (new Link (containerName1 , containerName1 + "Link" ))
357
+ )
347
358
.withName (containerName2 )
348
359
.withCmd ("env" )
349
- .withLinks (new Link (containerName1 , containerName1 + "Link" ))
350
360
.exec ();
351
361
352
362
LOG .info ("Created container {}" , container2 .toString ());
@@ -377,10 +387,11 @@ public void createContainerWithCustomIp() throws DockerException {
377
387
assertNotNull (createNetworkResponse .getId ());
378
388
379
389
CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
380
- .withNetworkMode (networkName )
381
390
.withCmd ("sleep" , "9999" )
391
+ .withHostConfig (newHostConfig ()
392
+ .withNetworkMode (networkName ))
382
393
.withName (containerName1 )
383
- .withIpv4Address (subnetPrefix +".100" )
394
+ .withIpv4Address (subnetPrefix + ".100" )
384
395
.exec ();
385
396
386
397
assertThat (container .getId (), not (isEmptyString ()));
@@ -410,8 +421,9 @@ public void createContainerWithAlias() throws DockerException {
410
421
assertNotNull (createNetworkResponse .getId ());
411
422
412
423
CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
413
- .withNetworkMode (networkName )
414
424
.withCmd ("sleep" , "9999" )
425
+ .withHostConfig (newHostConfig ()
426
+ .withNetworkMode (networkName ))
415
427
.withName (containerName1 )
416
428
.withAliases ("server" + dockerRule .getKind ())
417
429
.exec ();
@@ -430,8 +442,11 @@ public void createContainerWithAlias() throws DockerException {
430
442
@ Test
431
443
public void createContainerWithCapAddAndCapDrop () throws DockerException {
432
444
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 ();
435
450
436
451
LOG .info ("Created container {}" , container .toString ());
437
452
@@ -451,7 +466,9 @@ public void createContainerWithDns() throws DockerException {
451
466
String anotherDnsServer = "8.8.4.4" ;
452
467
453
468
CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCmd ("true" )
454
- .withDns (aDnsServer , anotherDnsServer ).exec ();
469
+ .withHostConfig (newHostConfig ()
470
+ .withDns (aDnsServer , anotherDnsServer ))
471
+ .exec ();
455
472
456
473
LOG .info ("Created container {}" , container .toString ());
457
474
@@ -487,7 +504,9 @@ public void createContainerWithExtraHosts() throws DockerException {
487
504
488
505
CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
489
506
.withName ("containerextrahosts" + dockerRule .getKind ())
490
- .withExtraHosts (extraHosts ).exec ();
507
+ .withHostConfig (newHostConfig ()
508
+ .withExtraHosts (extraHosts ))
509
+ .exec ();
491
510
492
511
LOG .info ("Created container {}" , container .toString ());
493
512
@@ -503,7 +522,8 @@ public void createContainerWithExtraHosts() throws DockerException {
503
522
public void createContainerWithDevices () throws DockerException {
504
523
505
524
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 ();
507
527
508
528
LOG .info ("Created container {}" , container .toString ());
509
529
@@ -517,7 +537,7 @@ public void createContainerWithDevices() throws DockerException {
517
537
518
538
@ Test
519
539
public void createContainerWithPortBindings () throws DockerException {
520
- int baseport = getFactoryType () == FactoryType .JERSEY ? 11000 : 12000 ;
540
+ int baseport = getFactoryType () == FactoryType .JERSEY ? 11000 : 12000 ;
521
541
522
542
ExposedPort tcp22 = ExposedPort .tcp (22 );
523
543
ExposedPort tcp23 = ExposedPort .tcp (23 );
@@ -528,7 +548,8 @@ public void createContainerWithPortBindings() throws DockerException {
528
548
portBindings .bind (tcp23 , Binding .bindPort (baseport + 24 ));
529
549
530
550
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 ();
532
553
533
554
LOG .info ("Created container {}" , container .toString ());
534
555
@@ -581,7 +602,8 @@ public void createContainerWithLinking() throws DockerException {
581
602
582
603
CreateContainerResponse container2 = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCmd ("sleep" , "9999" )
583
604
.withName (containerName2 )
584
- .withLinks (new Link (containerName1 , containerName1 + "Link" )).exec ();
605
+ .withHostConfig (newHostConfig ()
606
+ .withLinks (new Link (containerName1 , containerName1 + "Link" ))).exec ();
585
607
586
608
LOG .info ("Created container2 {}" , container2 .toString ());
587
609
assertThat (container2 .getId (), not (isEmptyString ()));
@@ -608,7 +630,8 @@ public void createContainerWithRestartPolicy() throws DockerException {
608
630
RestartPolicy restartPolicy = RestartPolicy .onFailureRestart (5 );
609
631
610
632
CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCmd ("sleep" , "9999" )
611
- .withRestartPolicy (restartPolicy ).exec ();
633
+ .withHostConfig (newHostConfig ()
634
+ .withRestartPolicy (restartPolicy )).exec ();
612
635
613
636
LOG .info ("Created container {}" , container .toString ());
614
637
@@ -623,7 +646,8 @@ public void createContainerWithRestartPolicy() throws DockerException {
623
646
public void createContainerWithPidMode () throws DockerException {
624
647
625
648
CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCmd ("true" )
626
- .withPidMode ("host" ).exec ();
649
+ .withHostConfig (newHostConfig ()
650
+ .withPidMode ("host" )).exec ();
627
651
628
652
LOG .info ("Created container {}" , container .toString ());
629
653
@@ -644,7 +668,8 @@ public void createContainerWithPidMode() throws DockerException {
644
668
public void createContainerWithNetworkMode () throws DockerException {
645
669
646
670
CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE ).withCmd ("true" )
647
- .withNetworkMode ("host" ).exec ();
671
+ .withHostConfig (newHostConfig ()
672
+ .withNetworkMode ("host" )).exec ();
648
673
649
674
LOG .info ("Created container {}" , container .toString ());
650
675
@@ -677,7 +702,8 @@ public void createContainerWithULimits() throws DockerException {
677
702
678
703
CreateContainerResponse container = dockerRule .getClient ().createContainerCmd (DEFAULT_IMAGE )
679
704
.withName (containerName )
680
- .withUlimits (ulimits ).exec ();
705
+ .withHostConfig (newHostConfig ()
706
+ .withUlimits (ulimits )).exec ();
681
707
682
708
LOG .info ("Created container {}" , container .toString ());
683
709
@@ -720,7 +746,10 @@ public void createContainerWithLabels() throws DockerException {
720
746
public void createContainerWithLogConfig () throws DockerException {
721
747
722
748
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 ();
724
753
725
754
LOG .info ("Created container {}" , container .toString ());
726
755
@@ -789,7 +818,8 @@ public void onNext(Frame item) {
789
818
@ Test
790
819
public void createContainerWithCgroupParent () throws DockerException {
791
820
CreateContainerResponse container = dockerRule .getClient ().createContainerCmd ("busybox" )
792
- .withCgroupParent ("/parent" ).exec ();
821
+ .withHostConfig (newHostConfig ()
822
+ .withCgroupParent ("/parent" )).exec ();
793
823
794
824
LOG .info ("Created container {}" , container .toString ());
795
825
0 commit comments