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.

  • Lift Sails inside Docker container
  • How to start mysql server in docker container
  • Does the Docker RPM require additional dependencies?
  • docker 1.12 swarm : Does Swarm have a configuration store like kubernetes configMap
  • Docker Postgres data volume on the host
  • How to handle IP addresses when linking docker containers with each other using docker-compose?
  • 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 !

  • boot2docker / docker “Error. image library/.:latest not found”
  • Guidance needed - how to track nginx-docker-rails performance issue
  • Does docker support command aliases similar to Git aliases?
  • openconnect in dockers/IBM bluemix (Error: TUNSETIFF failed: Inappropriate ioctl for device)
  • docker mysql connection via php
  • Docker with App_Data volume?
  • 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.