- Home
- Operations Guide
- Deploy applications with Swarm
- Deploy a multi-service application
Deploy a multi-service application#
This topic describes how to use both the MKE web UI and the CLI to deploy a multi-service application for voting on whether you prefer cats or dogs.
To deploy a multi-service application using the MKE web UI:
-
Log in to the MKE web UI.
-
Navigate to Shared Resources > Stacks and click Create Stack.
-
In the Name field, enter
voting-app. -
Under ORCHESTRATOR MODE, select Swarm Services and click Next.
-
In the Add Application File editor, paste the following application definition written in the
docker-compose.ymlformat:version: "3" services: # A Redis key-value store to serve as message queue redis: image: redis:alpine ports: - "6379" networks: - frontend # A PostgreSQL database for persistent storage db: image: postgres:9.4 volumes: - db-data:/var/lib/postgresql/data networks: - backend # Web UI for voting vote: image: dockersamples/examplevotingapp_vote:before ports: - 5000:80 networks: - frontend depends_on: - redis # Web UI to count voting results result: image: dockersamples/examplevotingapp_result:before ports: - 5001:80 networks: - backend depends_on: - db # Worker service to read from message queue worker: image: dockersamples/examplevotingapp_worker networks: - frontend - backend networks: frontend: backend: volumes: db-data: -
Click Create to deploy the stack.
-
In the list on the Shared Resources > Stacks page, verify that the application is deployed by looking for voting-app. If the application is in the list, it is deployed.
-
To view the individual application services, click voting-app and navigate to the Services tab.
-
Cast votes by accessing the service on port
5000.
Caution
-
MKE does not support referencing external files when using the MKE web UI to deploy applications, and thus does not support the following keywords:
-
build
-
dockerfile
-
env_file
-
-
You must use a version control system to store the stack definition used to deploy the stack, as MKE does not store the stack definition.
To deploy a multi-service application using the MKE CLI:
-
Create a file named
docker-compose.ymlwith the following content:version: "3" services: # A Redis key-value store to serve as message queue redis: image: redis:alpine ports: - "6379" networks: - frontend # A PostgreSQL database for persistent storage db: image: postgres:9.4 volumes: - db-data:/var/lib/postgresql/data networks: - backend environment: - POSTGRES_PASSWORD=<password> # Web UI for voting vote: image: dockersamples/examplevotingapp_vote:before ports: - 5000:80 networks: - frontend depends_on: - redis # Web UI to count voting results result: image: dockersamples/examplevotingapp_result:before ports: - 5001:80 networks: - backend depends_on: - db # Worker service to read from message queue worker: image: dockersamples/examplevotingapp_worker networks: - frontend - backend networks: frontend: backend: volumes: db-data: -
Create the application:
docker stack deploy --compose-file docker-compose.yml voting-appdocker-compose --file docker-compose.yml --project-name voting-app up -d -
Verify that the application is deployed:
docker stack ps voting-app -
Cast votes by accessing the service on port
5000.