0

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 :(

istoOi
  • 1
  • 1
  • In addition to the duplicate link, [BashFAQ/050](http://mywiki.wooledge.org/BashFAQ/050) is also a good read for this problem. – tjm3772 Mar 23 '23 at 17:44

0 Answers0