mysqlbashdockerdocker-exec

Bash scripting with docker exec when using variables


I'm trying to create a Bash script based on variables. It works well when I'm using bash command line via docker image:

#docker exec app_mysql mysqldump --login-path=localroot masterdb | gzip > 1111111.sql.gz 

While I'm trying to reproduce the same via shell script by using variables it gives me nothing but just executes without any errors:

#!/bin/bash

DOCKER="docker exec app_mysql bash -c"
CONF_LOCAL_MYSQL_ROOT="--login-path=localroot"
LOCALDBNAME="masterdb"

$DOCKER '(mysqldump '$CONF_LOCAL_MYSQL_ROOT' '$LOCALDBNAME' | gzip > '${LOCALDBNAME}'_local_'${DATE}'.sql.gz)'

Where I'm wrong?


Solution

  • Bash variables are not expanded inside single-quotes.

    $ foo=hello
    
    $ echo '$foo'
    $foo
    
    $ echo "$foo"
    hello