podman icon indicating copy to clipboard operation
podman copied to clipboard

Make `--tty` copy `$TERM` instead of setting it to `xterm`

Open dseomn opened this issue 8 months ago • 3 comments

Feature request description

It looks like podman currently sets $TERM to xterm when --tty is specified (#20357). Would it be possible to instead copy it from the host, like ssh does? That way programs in the container could access the terminal correctly regardless of the terminal that podman is run from.

Suggest potential solution

Copy $TERM from the host if --tty is specified and $TERM isn't already set anywhere else.

Have you considered any alternatives?

Putting this in ~/.config/containers/containers.conf works, though it copies $TERM even when --tty isn't specified.

[containers]
env = ["TERM", {append=true}]

Additional context

No response

dseomn avatar Mar 25 '25 19:03 dseomn

It looks like the alternative/workaround doesn't work very well, because of #25685. If this feature request is implemented, then that solves my problem. But if not, would it be possible to instead add a new containers.conf setting for environment variables that are set/copied by both podman run and podman exec?

dseomn avatar Mar 26 '25 16:03 dseomn

Putting this in ~/.config/containers/containers.conf works, though it copies $TERM even when --tty isn't specified.

what is the downside of setting TERM when --tty is not specified?

giuseppe avatar Mar 28 '25 12:03 giuseppe

what is the downside of setting TERM when --tty is not specified?

For my current use case, that would be fine if it worked.

In general, it does leak some information from the host into the container. It's probably not very valuable information, but still probably worth not leaking for no reason.

I'm also not sure what TERM would mean without a TTY. I'm guessing it would just be ignored by most apps?

dseomn avatar Mar 28 '25 15:03 dseomn

I'm also not sure what TERM would mean without a TTY. I'm guessing it would just be ignored by most apps?

I expect it to be ignored since it’s meaningless without a terminal. This makes handling of TERM simpler, we can treat it like any other environment variable instead of making it conditional with --tty

giuseppe avatar Mar 31 '25 10:03 giuseppe

Hello, Is this feature request still reasonable? If so can I work on it?

arsenalzp avatar Apr 28 '25 09:04 arsenalzp

I think this first needs some kind of closer analyzation of what impact using the host env by default could have, i.e. how does this effect docker compat or other compatibility aspects for the containers, is there a chance this could break anything?

One thing to note is that podman could be used as multiplexer, i.e. you can start the container from on terminal and the later use podman attach from another (and of course you cannot update the TERM env later). And with the current podman code TERM is set when we create the container once to its value and not changed on start. So to have proper copy logic one would have to write this fully into libpod so we can lookup the env on each start.

So overall not something trivial to implement assuming we would even want to change, I am not sure on that.

Luap99 avatar Apr 28 '25 10:04 Luap99

But if not, would it be possible to instead add a new containers.conf setting for environment variables that are set/copied by both podman run and podman exec?

Would it make more sense to do this, if copying TERM by default is complicated?

dseomn avatar Apr 28 '25 17:04 dseomn

I've tried editing [engine] and [containers] in the VM .config and /etc and on the host mac .config, I've tried default_env and env directives... and I've found only one way to set TERM from outside the container (podman exec --env). There should be a way to configure this without having to resort to extra options or aliases. Copying in $TERM would be great, but the current behaviour always overrides with xterm - is there any way at all to set a hardcoded value or copy $TERM when doing a vanilla podman exec -it ?

j-h-a avatar Nov 07 '25 01:11 j-h-a