Building a Docker Application Stack

1 hour
  • 2 Learning Objectives

About this Hands-on Lab

Stacks are one of the most powerful orchestration features available in Docker Swarm. They allow you to easily manage complex applications consisting of multiple interdependent components running in separate containers.

In this lab, you will have the opportunity to work with Docker stacks by building a multi-component application as a Docker stack. You will also learn how to manage existing stacks by scaling a stack’s services after it has already been deployed. This will give you some hands-on insight into Docker stacks.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Build and deploy the application stack.
  1. Create an empty project directory with a Docker compose YAML file inside.

    cd ~/
    mkdir produce
    cd produce
    vi produce.yml
  2. Build a stack definition in produce.yml to meet the provided specifications.

    version: '3'
    services:
     fruit:
       image: linuxacademycontent/fruit-service:1.0.1
     vegetables:
       image: linuxacademycontent/vegetable-service:1.0.0
     all_products:
       image: linuxacademycontent/all-products:1.0.0
       ports:
       - "8080:80"
       environment:
       - FRUIT_HOST=fruit
       - FRUIT_PORT=80
       - VEGETABLE_HOST=vegetables
       - VEGETABLE_PORT=80
  3. Deploy the stack using the compose file.

    docker stack deploy -c produce.yml produce
  4. Verify that the stack is working.

    curl localhost:8080

    Note that after deploying, it may take a few moments for the stack to become responsive. You can check the status of the services with docker stack services produce. Once the services are up and running, you should get some JSON data containing a combined list of fruits and vegetables.

Scale the Fruit and Vegetable services in the stack.
  1. Set the number of replicas to 3 for the Fruit and Vegetable services in the compose file.

    vi produce.yml
    version: '3'
    services:
     fruit:
       image: linuxacademycontent/fruit-service:1.0.1
       deploy:
         replicas: 3
     vegetables:
       image: linuxacademycontent/vegetable-service:1.0.0
       deploy:
         replicas: 3
     all_products:
       image: linuxacademycontent/all-products:1.0.0
       ports:
       - "8080:80"
       environment:
       - FRUIT_HOST=fruit
       - FRUIT_PORT=80
       - VEGETABLE_HOST=vegetables
       - VEGETABLE_PORT=80
  2. Redeploy the stack using the compose file.

    docker stack deploy -c produce.yml produce
  3. Verify that the stack is still working.

    curl localhost:8080

    You should get some JSON data containing a combined list of fruits and vegetables.

    Use docker stack services produce to see that the number of replicas for the Fruit and Vegetable services is now 3.

Additional Resources

Your supermarket company is in the process of improving their Docker-based applications. They have built a set of three RESTful data services that communicate with each other as part of a larger infrastructure. You have been given the task of designing a Docker application stack so that these three services can be easily managed and scaled as a unit. A Docker Swarm cluster has already been set up for you to use.

Here is some background information on the three services:

  1. Fruit Service
    • Provides a list of fruits sold in the company's stores.
    • You can use the Docker image tag linuxacademycontent/fruit-service:1.0.1 to run this service.
    • Listens on port 80.
    • The service should be named fruit inside the stack.
  2. Vegetable Service
    • Provides a list of vegetables sold in the company's stores.
    • You can use the Docker image tag linuxacademycontent/vegetable-service:1.0.0 to run this service.
    • Listens on port 80.
    • The service should be named vegetables inside the stack.
  3. All Products Service
    • Queries the other two services, combining their data into a single list of all produce.
    • You can use the Docker image tag linuxacademycontent/all-products:1.0.0 to run this service.
    • Listens on port 80.
    • Use the environment variables FRUIT_HOST and FRUIT_PORT to set the host and port which will be used to query the fruit service.
    • Use the environment variables VEGETABLE_HOST and VEGETABLE_PORT to set the host and port which will be used to query the vegetable service.

Step 1

Deploy a Docker application stack that meets the following specifications:

  • The stack is called produce.
  • The stack runs the Fruit, Vegetable, and All Products services.
  • The All Products service is able to query the Fruit and Vegetable services.
  • The All Products service is published on port 8080.

One you have deployed the stack, you can verify whether it is working by querying the All Products service:

curl localhost:8080

If the stack is set up correctly, you should get a combined list of fruits and vegetables.

Step 2

Once you have deployed the stack and verified that it is working, modify the stack by scaling both the Fruit and Vegetable services up to 3 replicas.

If you get stuck, feel free to check out the solution video, or the detailed instructions under each objective. Good luck!

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?