I want to suffix a file name with the current date in my docker-compose.yml file. The end goal being a file such as my_log_123456789.log, where 123456789 is the current unix date.
I tried using an .env file, but that did not evaluate as expected. My attempt was:
# .env
NOW="$(date +%s)"
# docker-compose.yml
version: '3.8'
services:
xxx:
container_name: xxx
image: xxx/xxx
volumes:
- /home/ubuntu/xxx_"$(NOW)".log:/home/ubuntu/xxx.log
...
I tried a few variations of this and had the following issues:
ERROR: Invalid interpolation format for "volumes" option in service "xxx": "/home/ubuntu/xxx_$(NOW).log:/home/ubuntu/xxx.log"- A directory was created that was named
'xxx_"$(date +%s)".log'
How can I append the current date to a log file in a docker-compose.yml file?
docker-compose run -e VAR=VAL.NOWout of.envNOW="$(date +%s)" sudo docker-compose up -dproduces a directoryxxx_NOW.log/