Resolving env inside another env

So i would like to print my env variable which contains other variables.
For example i have:

MY_VARS="My var are:\nVAR1 = ${MY_VAR1}\nVAR2 = ${MY_VAR2}"

and i would like to make it possible in way like:

  • Can I setup a remote spark server inside docker so that I can communicate with it locally?
  • Running a cronjob or task inside a docker cloud container
  • Docker-compose networking, access host port from container
  • How to put sidekiq into Docker in a rails application?
  • Sync folder in docker image from Jhipster
  • How to mount current directory as read-only but still allow changes inside the container?
  • printf "${MY_VARS}" > my.conf


    printf "$(echo ${MY_VARS})" > my.conf

    to get sth like in my.conf file:

    My var are:
    VAR1 = var1
    VAR2 = var2

    but it dosent work.
    Is ther possibility to do such thing ?
    I need it to us it with Kubernetes so i can set env in my ReplicationController and use it with Kubernetes envs like SERVICE_HOST and SERVICE_PORT
    There is another problem that Kubernetes is changing my MY_VARS variable to multiline inside container so it looks like:

    MY_VARS=My var are:
    VAR1 = ${MY_VAR1}
    VAR2 = ${MY_VAR2}

    Hope it’s quite clear 🙂

    My solution:

    while read -r line
      printf "$line\n" >> conf.tmp
    done <<< "$CONFIG"
    while read -r line
      eval echo $line >> conf
    done < conf.tmp

    Where CONFIG variable is passed by me to the container and this variable contains Kubernetes service variables with IPs and Ports.
    I had to make it twice because eval couldnt resolve \n.

  • Commit to jenkins docker image does not save changes
  • How do debug multiple core services in containers from Visual Studio Mac
  • Creating a bootstrap Dockerfile that automatically exposes files to the host operating system
  • Setting up redis with docker
  • How to create and run docker container with new user other than root?
  • Need docker to build docker?
  • 2 Solutions collect form web for “Resolving env inside another env”

    With bash you can perform indirect references but it would not replace the value of your variable directly, only when you use it from a bash terminal.

    You’ve got to define the vars first. The following script prints out what you want:

    MY_VARS="My var are:\nVAR1 = ${MY_VAR1}\nVAR2 = ${MY_VAR2}"
    printf "${MY_VARS}"
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.