1

I have been doing a lot of work using Linux containers, and I keep forgetting which of the terminals on my screen is running inside which container, particularly when I leave them open overnight.

How can I change the shell prompt, or the terminal title based on the container that the shell runs in?

This is a general question, but it'd be great if it worked for systemd-nspawn and kde on Arch.

1 Answers1

1

Make sure your containers use distinct UTS namespaces then set a unique hostname in each one. For instance, things like docker set the hostname value to the container hash ID as a default in the UTS namespace associated with the main container process.

Thus with a PS1 pattern using the hostname variable you will know in which container you are when running a bash prompt.

Xavier Lucas
  • 13,505