Featured resource
Forrester Wave Report 2025
Pluralsight named a Leader in the Forrester Wave™

Our tech skill development platform earned the highest scores possible across 11 criteria.

Learn more
  • Labs icon Lab
  • Cloud
Google Cloud Platform icon
Labs

Building a Docker Application Stack

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.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 1h 0m
Published
Clock icon Jun 06, 2019

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    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
    
    1. 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
    
    
    1. Deploy the stack using the compose file.
    docker stack deploy -c produce.yml produce
    
    1. 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.

  2. Challenge

    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
    
    1. Redeploy the stack using the compose file.
    docker stack deploy -c produce.yml produce
    
    1. 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.

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.