Get Container name from within Container

Hi,

I’m trying to determine the container name I am in … this seems like an incredibly useful and necessary feature but for the life of me I can’t figure out where I can get the container name from within the container.

Docker seems to drop it into the hostname and as an env variable, but with silverblue/toolbox THAT is stripped down to be just “toolbox” and nothing else.

I NEED to know the full container name or ID.

Thanks :slight_smile:

Hi @chromakey
I was just reading another topic that has the solution to what you need

I tried it, and it seems to work for me.

 ⬢[mike@toolbox ~]$ flatpak-spawn --host podman ps
CONTAINER ID  IMAGE                                             COMMAND               CREATED      STATUS             PORTS  NAMES
c221218d8e2a  registry.fedoraproject.org/f31/fedora-toolbox:31  toolbox --verbose...  7 weeks ago  Up 39 seconds ago         fedora-toolbox-31
1 Like

WOW that was quick!

Have a friend working on a project (silver … it’s like powerline and all those fancy bash prompt thingies) … so will pass this onto him and you just made both of our days!

I’d try this right now but it looks like my 'effery with the toolbox system has it good and properly borked so about to do a total reinstall :confused:

What I wonder though, is how does toolbox magically know this information. It must be stored somewhere in a file or something as well … or maybe toolbox also has low-level access to the container system just like podman would.

Regardless … thank you SO much!!!

You’re welcome and welcome to the community.
I am no expert on toolbox/podman, but from what I understand this trick runs the given command outside the container on the host. Not sure what security restrictions you might run into.