Search code examples
amazon-web-servicesdockerenvironment-variablesdockerfileamazon-ecs

How to put ECS Docker Container ID into a Environmental Variable inside the Container


Hi I dont know if this is possible but I have a docker container in aws

[ec2-user@ip-10-200-40-182 ~]$ docker ps
CONTAINER ID        IMAGE                                                                                                                                                                            
74566049de08        xxxxxx.xxxxx.io/customers/xxxxxxx/lin/ema:5.0.6

I want to take that container ID and put it in a environmental variable inside that docker container

This needs to be dynamic so everytime i bounce the ecs service the environmental variable should automatically change.

I tried to do this in the dockerfile

FROM xxxxxxxxxxx.xxxx.ecr.eu-west-1.amazonaws.com/xxxxxxxxx:xxxxxxx

RUN uname -n > /test/tmp.log && \
export test_JMX_MANAGEMENTNODEHOSTNAME=$(cat /test/tmp.log)

But everytime I got into the container and echo $test_JMX_MANAGEMENTNODEHOSTNAME I get $(cat /test/tmp.log) and not the container id.. I am abit new to docker so help would be appreciated thank you!


Solution

  • I managed to figure it out what I exactly needed to do, I just ran it through entrypoint in the dockerfile and it worked :)

    Also @Durja thanks for your info! Helped me figure out my next problem related to IP ☺️