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:

  1. Log in to the MKE web UI.

  2. Navigate to Shared Resources > Stacks and click Create Stack.

  3. In the Name field, enter voting-app.

  4. Under ORCHESTRATOR MODE, select Swarm Services and click Next.

  5. In the Add Application File editor, paste the following application definition written in the docker-compose.yml format:

    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:
    
  6. Click Create to deploy the stack.

  7. 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.

  8. To view the individual application services, click voting-app and navigate to the Services tab.

  9. 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:

  1. Download and configure the client bundle.

  2. Create a file named docker-compose.yml with 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:
    
  3. Create the application:

    docker stack deploy --compose-file docker-compose.yml voting-app
      
    docker-compose --file docker-compose.yml --project-name voting-app up -d
      
  4. Verify that the application is deployed:

    docker stack ps voting-app
    
  5. Cast votes by accessing the service on port 5000.