@@ -84,18 +84,49 @@ public void startContainerWithVolumes() throws DockerException {
8484 inspectContainerResponse = dockerClient .inspectContainerCmd (container
8585 .getId ()).exec ();
8686
87- VolumeBind [] volumeBinds = inspectContainerResponse .getVolumes ();
88- List <String > volumes = new ArrayList <String >();
89- for (VolumeBind bind :volumeBinds ){
90- volumes .add (bind .getContainerPath ());
91- }
92- assertThat (volumes , contains (volume1 .getPath (), volume2 .getPath ()));
87+ assertContainerHasVolumes (inspectContainerResponse , volume1 , volume2 );
9388
9489 assertThat (Arrays .asList (inspectContainerResponse .getVolumesRW ()),
9590 contains (volume1 , volume2 ));
9691
9792 }
9893
94+ @ Test
95+ public void startContainerWithVolumesFrom () throws DockerException {
96+
97+ Volume volume1 = new Volume ("/opt/webapp1" );
98+ Volume volume2 = new Volume ("/opt/webapp2" );
99+
100+ String container1Name = UUID .randomUUID ().toString ();
101+
102+ CreateContainerResponse container1 = dockerClient
103+ .createContainerCmd ("busybox" ).withCmd ("sleep" , "9999" )
104+ .withName (container1Name ).exec ();
105+ LOG .info ("Created container1 {}" , container1 .toString ());
106+
107+ dockerClient .startContainerCmd (container1 .getId ()).withBinds (
108+ new Bind ("/src/webapp1" , volume1 ), new Bind ("/src/webapp2" , volume2 )).exec ();
109+ LOG .info ("Started container1 {}" , container1 .toString ());
110+
111+ InspectContainerResponse inspectContainerResponse1 = dockerClient .inspectContainerCmd (
112+ container1 .getId ()).exec ();
113+
114+ assertContainerHasVolumes (inspectContainerResponse1 , volume1 , volume2 );
115+
116+
117+ CreateContainerResponse container2 = dockerClient
118+ .createContainerCmd ("busybox" ).withCmd ("sleep" , "9999" ).exec ();
119+ LOG .info ("Created container2 {}" , container2 .toString ());
120+
121+ dockerClient .startContainerCmd (container2 .getId ()).withVolumesFrom (container1Name ).exec ();
122+ LOG .info ("Started container2 {}" , container2 .toString ());
123+
124+ InspectContainerResponse inspectContainerResponse2 = dockerClient
125+ .inspectContainerCmd (container2 .getId ()).exec ();
126+
127+ assertContainerHasVolumes (inspectContainerResponse2 , volume1 , volume2 );
128+ }
129+
99130 @ Test
100131 public void startContainerWithDns () throws DockerException {
101132
0 commit comments