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:

  • Docker - start container with environments variables
  • docker build on a private git repo containing the Dockerfile?
  • What is the impact of using multiple Base Images in Docker?
  • The volumes always mount to the /root/ not /crawler/ I specified
  • CannotStartContainerError with node:6.7.0-wheezy on AWS
  • docker current not installed - bash on ubuntu on windows 10
  • 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.

  • Can I run windows containers using docker-toolbox on windows 7?
  • Restrict published port to a specific container with Docker
  • How to build a Docker container for JAVA web application
  • How to set a var for a Docker-compose file?
  • Docker container not starting (docker start)
  • How to remove multiple docker images with the same imageID?
  • 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.