How can I get docker's container name from inside the container?
I can't use "inspect" because I have to use a script from inside the container to get information from a JSON url.
A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.
If you mean the Container ID its available in the env as the hostname variable. It should be interchangeable with the name for most operations.
env
HOSTNAME=5252eb24b296
TERM=xterm
....
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5252eb24b296 ubuntu:14.04 "bash" 23 seconds ago Up 22 seconds test
If you want the container name rather than container id you can do a reverse DNS lookup on eth0 of the container.
dig -x `ifconfig eth0 | grep 'inet' | awk '{print $2}'` +short | cut -d'.' -f1
This gives you the friendly name rather than the id.
UPDATE: Only works if you have ifconfig
and dig
and other tools installed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With