Don’t Repeat Yourself with Anchors, Aliases and Extensions in Docker Compose Files

version: '3.3'
services:
web:
image: nginx
port:
- 80:80
app:
image: my-app
environment:
- DB_HOST=db
db:
image: postgres
services:
# Node.js gives OS info about the node (Host)
nodeinfo:
image: functions/nodeinfo:latest
labels:
function: "true"
depends_on:
- gateway
networks:
- functions
environment:
no_proxy: "gateway"
https_proxy: $https_proxy
deploy:
placement:
constraints:
- 'node.platform.os == linux'
# Uses `cat` to echo back response, fastest function to execute.
echoit:
image: functions/alpine:health
labels:
function: "true"
depends_on:
- gateway
networks:
- functions
environment:
fprocess: "cat"
no_proxy: "gateway"
https_proxy: $https_proxy
deploy:
placement:
constraints:
- 'node.platform.os == linux'
- &flag Apple
- Beachball
- Cartoon
- Duckface
- *flag
- Apple
- Beachball
- Cartoon
- Duckface
- Apple
services:
# Node.js gives OS info about the node (Host)
nodeinfo: &function
image: functions/nodeinfo:latest
labels:
function: "true"
depends_on:
- gateway
networks:
- functions
environment:
no_proxy: "gateway"
https_proxy: $https_proxy
deploy:
placement:
constraints:
- 'node.platform.os == linux'
# Uses `cat` to echo back response, fastest function to execute.
echoit:
<<: *function
image: functions/alpine:health
environment:
fprocess: "cat"
no_proxy: "gateway"
https_proxy: $https_proxy
# Basic function options
x-function: &function
labels:
function: "true"
depends_on:
- gateway
networks:
- functions
deploy:
placement:
constraints:
- 'node.platform.os == linux'
services:
# Node.js gives OS info about the node (Host)
nodeinfo:
<<: *function
image: functions/nodeinfo:latest
environment:
no_proxy: "gateway"
https_proxy: $https_proxy
# Uses `cat` to echo back response, fastest function to execute.
echoit:
<<: *function
image: functions/alpine:health
environment:
fprocess: "cat"
no_proxy: "gateway"
https_proxy: $https_proxy
# Basic function options
x-function: &function
labels:
function: "true"
depends_on:
- gateway
networks:
- functions
# Linux placement
x-linux: &linux-only
deploy:
placement:
constraints:
- 'node.platform.os == linux'
# Windows placement
x-windows: &windows-only
deploy:
placement:
constraints:
- 'node.platform.os == windows'
services:
# Node.js gives OS info about the node (Host)
nodeinfo:
<<: *function
<<: *linux-only
image: functions/nodeinfo:latest
environment:
no_proxy: "gateway"
https_proxy: $https_proxy
# Uses `cat` to echo back response, fastest function to execute.
echoit:
<<: *function
<<: *linux-only
image: functions/alpine:health
environment:
fprocess: "cat"
no_proxy: "gateway"
https_proxy: $https_proxy

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store