Created
September 19, 2023 15:39
-
-
Save ajdinmore/9d34f8f07e3faa5d5c86be045c68bb8f to your computer and use it in GitHub Desktop.
Docker Compose/Stack Placeholder Template Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#file: noinspection SpellCheckingInspection | |
# https://docs.docker.com/engine/reference/commandline/service_create/#create-services-using-templates | |
# https://docs.docker.com/config/containers/logging/awslogs/#tag | |
# https://docs.docker.com/config/containers/logging/log_tags/ | |
# https://forums.docker.com/t/example-usage-of-docker-swarm-template-placeholders/73859 | |
services: | |
service: | |
image: busybox | |
command: env | |
hostname: '{{.Task.Name}}-{{.Node.Hostname}}' | |
logging: | |
driver: awslogs | |
options: | |
awslogs-stream: '{{.Node.Hostname}}/{{.Task.Name}}' | |
## or | |
#tag: '{{.Node.Hostname}}/{{.Name}}' | |
awslogs-group: '{{.Service.Name}}/${STACK_ENV}' | |
awslogs-region: eu-west-2 | |
environment: | |
NODE_ID: '{{.Node.ID}}' | |
NODE_HOSTNAME: '{{.Node.Hostname}}' | |
SERVICE_ID: '{{.Service.ID}}' | |
SERVICE_NAME: '{{.Service.Name}}' | |
SERVICE_LABELS: '{{.Service.Labels}}' | |
TASK_ID: '{{.Task.ID}}' | |
TASK_NAME: '{{.Task.Name}}' | |
TASK_SLOT: '{{.Task.Slot}}' | |
STACK_NAMESPACE: '{{index .Service.Labels "com.docker.stack.namespace"}}' | |
## example values | |
# NODE_HOSTNAME=laptop | |
# NODE_ID=tsnacyg4e828z5zzrvzt2u6qq | |
# | |
# SERVICE_ID=jq94b58o6phfgbzmmo1zpqe5h | |
# SERVICE_LABELS=map[com.docker.stack.image:busybox com.docker.stack.namespace:stackname] | |
# SERVICE_NAME=stackname_test-service | |
# | |
# TASK_ID=y2o4gavzb8zg7jq40cjv6q6va | |
# TASK_NAME=stackname_test-service.1.y2o4gavzb8zg7jq40cjv6q6va | |
# TASK_SLOT=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment