Deploy services to a Swarm collection¶
This topic describes how to use both the CLI and a Compose file to deploy application resources to a particular Swarm collection. Attach the Swarm collection path to the service access label to assign the service to the required collection. MKE automatically assigns new services to the default collection unless you use either of the methods presented here to assign a different Swarm collection.
To assign services to Swarm collections, an administrator must first create the Swarm collection and grant the user access to the required collection. Otherwise the deployment will fail.
If required, you can place application resources into multiple collections.
To deploy a service to a Swarm collection using the CLI:
docker service create to deploy your service to a collection:
docker service create \ --name <service-name> \ --label com.docker.ucp.access.label="</collection/path>" <app-name>:<version>
To deploy a service to a Swarm collection using a Compose file:
labels:dictionary in a Compose file and add the Swarm collection path to the
The following example specifies two services, WordPress and MySQL, and assigns
/Shared/wordpressto their access labels:
version: '3.1' services: wordpress: image: wordpress networks: - wp ports: - 8080:80 environment: WORDPRESS_DB_PASSWORD: example deploy: labels: com.docker.ucp.access.label: /Shared/wordpress mysql: image: mysql:5.7 networks: - wp environment: MYSQL_ROOT_PASSWORD: example deploy: labels: com.docker.ucp.access.label: /Shared/wordpress networks: wp: driver: overlay labels: com.docker.ucp.access.label: /Shared/wordpress
Log in to the MKE web UI.
Navigate to the Shared Resources > Stacks and click Create Stack.
Name the application
Under ORCHESTRATOR MODE, select Swarm Services and click Next.
In the Add Application File editor, paste the Compose file.
Click Create to deploy the application
Click Done when the deployment completes.
MKE reports an error if the
/Shared/wordpress collection does not
exist or if you do not have a grant for accessing it.
To confirm that the service deployed to the correct Swarm collection:
Navigate to Shared Resources > Stacks and select your application.
Navigate to the to Services tab and select the required service.
On the details pages, verify that the service is assigned to the correct Swarm collection.
MKE creates a default
overlay network for your stack that attaches to
each container you deploy. This works well for administrators and those
assigned full control roles. If you have lesser permissions, define a custom
network with the same
com.docker.ucp.access.label label as your services
and attach this network to each service. This correctly groups your network
with the other resources in your stack.