This also works in docker-compose files here’s an example of how I did it with Visual Studio Team Services agents
# sudo docker stack deploy -c vsts-agent.yml --prune vsts-agent
version: '3.4'
services:
agent:
image: microsoft/vsts-agent:ubuntu-16.04-docker-17.12.0-ce-standard
environment:
- VSTS_ACCOUNT=trajano
- VSTS_AGENT={{.Task.Name}}
- VSTS_POOL=Default
- TFS_HOST=trajano.visualstudio.com
- VSTS_TOKEN=secret
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
deploy:
replicas: 2
A list of template values are here