44import com .github .dockerjava .api .model .ContainerSpec ;
55import com .github .dockerjava .api .model .EndpointResolutionMode ;
66import com .github .dockerjava .api .model .EndpointSpec ;
7+ import com .github .dockerjava .api .model .Mount ;
8+ import com .github .dockerjava .api .model .MountType ;
79import com .github .dockerjava .api .model .Network ;
810import com .github .dockerjava .api .model .NetworkAttachmentConfig ;
911import com .github .dockerjava .api .model .PortConfig ;
1416import com .github .dockerjava .api .model .ServiceSpec ;
1517import com .github .dockerjava .api .model .SwarmSpec ;
1618import com .github .dockerjava .api .model .TaskSpec ;
19+ import com .github .dockerjava .api .model .TmpfsOptions ;
1720import com .google .common .collect .ImmutableMap ;
1821import com .google .common .collect .Lists ;
1922import org .junit .Test ;
2023import org .slf4j .Logger ;
2124import org .slf4j .LoggerFactory ;
2225
26+ import java .util .Collections ;
2327import java .util .List ;
2428
2529import static com .github .dockerjava .junit .DockerRule .DEFAULT_IMAGE ;
@@ -44,7 +48,7 @@ public void testCreateService() throws DockerException {
4448 .withTaskTemplate (new TaskSpec ()
4549 .withContainerSpec (new ContainerSpec ()
4650 .withImage (DEFAULT_IMAGE ))))
47- .exec ();
51+ .exec ();
4852
4953 List <Service > services = dockerRule .getClient ().listServicesCmd ()
5054 .withNameFilter (Lists .newArrayList (SERVICE_NAME ))
@@ -79,7 +83,7 @@ public void testCreateServiceWithNetworks() {
7983 .withTarget (networkId )
8084 .withAliases (Lists .<String >newArrayList ("alias1" , "alias2" ))
8185 ))
82- .withLabels (ImmutableMap .of ("com.docker.java.usage" ,"SwarmServiceIT" ))
86+ .withLabels (ImmutableMap .of ("com.docker.java.usage" , "SwarmServiceIT" ))
8387 .withMode (new ServiceModeConfig ().withReplicated (
8488 new ServiceReplicatedModeOptions ()
8589 .withReplicas (1 )
@@ -104,4 +108,29 @@ public void testCreateServiceWithNetworks() {
104108 dockerRule .getClient ().removeServiceCmd (SERVICE_NAME ).exec ();
105109 }
106110
111+ @ Test
112+ public void testCreateServiceWithTmpfs () {
113+ dockerRule .getClient ().initializeSwarmCmd (new SwarmSpec ())
114+ .withListenAddr ("127.0.0.1" )
115+ .withAdvertiseAddr ("127.0.0.1" )
116+ .exec ();
117+ Mount tmpMount = new Mount ().withTmpfsOptions (new TmpfsOptions ().withSizeBytes (600L )).withTarget ("/tmp/foo" );
118+
119+ dockerRule .getClient ().createServiceCmd (new ServiceSpec ()
120+ .withName (SERVICE_NAME )
121+ .withTaskTemplate (new TaskSpec ()
122+ .withContainerSpec (new ContainerSpec ().withImage (DEFAULT_IMAGE ).withMounts (Collections .singletonList (tmpMount )))))
123+ .exec ();
124+
125+ List <Service > services = dockerRule .getClient ().listServicesCmd ()
126+ .withNameFilter (Lists .newArrayList (SERVICE_NAME ))
127+ .exec ();
128+
129+ assertThat (services , hasSize (1 ));
130+ List <Mount > mounts = dockerRule .getClient ().inspectServiceCmd (SERVICE_NAME ).exec ().getSpec ().getTaskTemplate ()
131+ .getContainerSpec ().getMounts ();
132+ assertThat (mounts , hasSize (1 ));
133+ assertThat (mounts .get (0 ), is (tmpMount ));
134+ dockerRule .getClient ().removeServiceCmd (SERVICE_NAME ).exec ();
135+ }
107136}
0 commit comments