I’m trying access the container name at runtime in my startup script in order to improve telemetry from my container.
In order to do this, my container needs to be aware of its name at runtime. Is there a way to dynamically set the container name as a runtime environment variable (via
docker run -e or
docker-compose for example)?
Otherwise, is it possible for the container to find its own name by communicating with the docker engine? I’ve looked at this stackoverflow question and it looks like it’s possible to get the container name via the docker engine api using the container id which is available by default via powershell as
$env:COMPUTERNAME. The stackoverflow post gives ways to do this on linux containers but I haven’t found out how to do this via powershell on windows containers.