Reputation: 4504
Is there a way to set a variable from a file in the docker compose?
The following does not work in compose (however it does if you attach to the container):
version: '2'
services:
foo:
image: busybox
command:
- /bin/sh
- -c
- |
echo "hello" > id #this file will be supplied by a volume-from
ls
cat id
TEST=$(cat id) #This line does not work
echo TEST
The error which is produced is:
ERROR: Invalid interpolation format for "command" option in service "foo":
Upvotes: 0
Views: 132
Reputation: 60036
you have to change a bit your config file.
version: '2'
services:
foo:
image: busybox
command:
- /bin/sh
- -c
- |
echo "hello" > id
ls
cat id
TEST=$$(cat id)
echo TEST
I checked against Docker Version Docker version 18.06.0-ce
and Docker compose version docker-compose version 1.20.0-rc2,
You can use a $$ (double-dollar sign) when your configuration needs a literal dollar sign. This also prevents Compose from interpolating a value, so a $$ allows you to refer to environment variables that you don’t want processed by Compose.
Upvotes: 1