- Lab
- A Cloud Guru
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.
Path Info
Table of Contents
-
Challenge
Build and deploy the application stack.
- Create an empty project directory with a Docker compose YAML file inside.
cd ~/ mkdir produce cd produce vi produce.yml
- 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
- Deploy the stack using the compose file.
docker stack deploy -c produce.yml produce
- 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. -
Challenge
Scale the Fruit and Vegetable services in the stack.
- 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
- Redeploy the stack using the compose file.
docker stack deploy -c produce.yml produce
- 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. - Set the number of replicas to
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.