Skip to content

Instantly share code, notes, and snippets.

@elowy01
Last active April 9, 2020 11:00
Show Gist options
  • Save elowy01/63b7e371cc3a1f11f3c953eb1e7668c6 to your computer and use it in GitHub Desktop.
Save elowy01/63b7e371cc3a1f11f3c953eb1e7668c6 to your computer and use it in GitHub Desktop.
# You need a .yaml file with the stack definition:
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
This stack will contain 3 services (see names 'fruit','vegetables' and 'all_products')
'all_products' will listen on 8080 and also will have 3 environment variables defined
# Now you can deploy the stack:
# where 'produce' will be the stack name
# Now we can check the status of the stack by doing:
docker stack services produce
And we get:
ID NAME MODE REPLICAS IMAGE PORTS
95d3a3g0yjq8 produce_fruit replicated 1/1 linuxacademycontent/fruit-service:1.0.1
ikqsmzenjgd0 produce_vegetables replicated 1/1 linuxacademycontent/vegetable-service:1.0.0
oyuct2ubwe06 produce_all_products replicated 1/1 linuxacademycontent/all-products:1.0.0 *:8080->80/tcp
# Now, set the number of replicas to 3 for the Fruit and Vegetable services in the compose file:
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment