i have a bash script which should start a docker container remotely. The Systems are Debian 11 with docker 20.10.21.
The simplified part:
#!/bin/bash
$VAR="lorem"
RUN="run --name foo -d --net=host -e VAR1=foo -e VAR2=\"${VAR} ipsum dolor\" VAR3=bar arcts/keepalived:1.2.2"
docker -H tcp://1.2.3.4:2375 ${RUN}
If i echo out the command i get
docker -H tcp://1.2.3.4:2375 run --name foo -d --net=host -e VAR1=foo -e VAR2="lorem ipsum dolor" VAR3=bar arcts/keepalived:1.2.2
which seems correct. However, if i run the script i get the following error:
Unable to find image 'ipsum:latest' locally
If i run the echoed out command manually in the terminal it works.
I assume that within the bash script the quotes get lost and docker thinks that VAR2 is just "lorem" and the next word "ipsum" is therefore the name of the image. I tried single quotes
VAR2='${VAR} ipsum dolor'
More escaping
VAR2=\\\"${VAR} ipsum dolor\\\"
but nothing works :(