Setting Dynamic Env variable in Docker

I am trying to set dynamic env variable in Docker but somehow it resets.
I want to set an ENV variable which has value :

export EC2_Region=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone) 

so i cant just use ENV in Dockerfile since its not static.

  • Sandbox command execution with docker via Ajax
  • Backup/Restore a dockerized PostgreSQL database
  • How do I access a USB drive on a OSX host from inside a docker container?
  • Bamboo Mesos Marathon
  • how to link two single container AWS Elastic Beanstalk environments
  • Possible to host private docker registries?
  • I tried making an init.sh and used CMD["init.sh"] in Dockerfile but when i attach to the docker process, the env variable is empty.

    I am fairy new to docker and still exploring options.

    Thanks in advance !

  • docker-compose links between app and db
  • How can I make /etc/hosts writable by root in a Docker Container?
  • docker suspend and resume using criu
  • create-react-app + docker = QA and PROD Deploy
  • Google cloud sdks doesn't start preview for Docker image Mac OS
  • Dockerizing PostgreSQL
  • One Solution collect form web for “Setting Dynamic Env variable in Docker”

    You can use ENTRYPOINT instead of CMD.

    Example Dockerfile:

    FROM ubuntu:14.04
    COPY init.sh /
    RUN chmod +x /init.sh
    ENTRYPOINT ["/init.sh"]
    

    init.sh:

    export EC2_Region=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.