I created a custom docker container, which calls a startup script. That script requires some data, which is stored in my .env file.
All variables required by all files are stored in .env, and that is where I want to keep it. I can pass variables this way without error... it's only arrays that I can't pass correctly.
.env:
FOO=1 # blah
BAR='bar' # this does blah
MYARRAY=(
hello # blah
world # blah
)
docker-compose.yml:
mycontainer:
env_file: .env
build:
context: .
args: # pass variables into dockerfile
FOO: ${FOO}
MYARRAY: ${MYARRAY}
Dockerfile:
FROM some_app
ARG FOO
ARG MYARRAY
ENV \
FOO=$FOO \
MYARRAY=$MYARRAY # pass variables into script
CMD [ "myscript.sh" ]
myscript.sh:
#!/bin/bash
set -Eeuo pipefail
echo "$FOO" # works
for i in "${MYARRAY[@]}"; do echo "$i"; done # <---- problem is here
The array does not arrive intact in the script - it arrives as "(". This is because it is "translated" from ini to yaml to dockerfile syntax to bash.
How do I escape/format the stuff in .env so that it arrives in the bash script correctly?