by kh_hk · 4y ago · 0 comments
services:
redis:
...
{{ if some_condition }}
volumes:
bla bla
{{ end if }}
{{ if some_other_condition }}
another_service:
...
{{ end if }}
volumes:
{{ for volume in volumes }}
- ...
{{ end for }}This feels like it's a very incorrect solution to a problem that you're making far more complicated than it needs to be.
The following is just a contrived example. Why would I do that? Because I can
# Bring up services without a command
#
# usage:
# nocmd.sh up -d service_name
function _compose {
docker-compose -f docker-compose.yml $@
}
function nocmd {
cat << EOF
services:
$1:
command: tail -f /dev/null
EOF
}
function nocmd_compose {
local service=${@: -1}
_compose -f <(nocmd "$service") $@
}
nocmd_compose $@