Docker bash提示不显示颜色输出 [英] Docker bash prompt does not display color output
问题描述
我使用命令:docker run --rm -it govim bash -l
运行docker镜像,但是
它不显示颜色输出.如果我source ~/.bash_profile
或再次运行bash -l
,则输出将正确以彩色输出.
I use command: docker run --rm -it govim bash -l
to run docker images but
it does not display color output. If I source ~/.bash_profile
or run bash -l
again, output will then correctly be output with color.
推荐答案
OP SolomonT 报告 docker run
与
The OP SolomonT reports that docker run
with env
do work:
docker run --rm -it -e "TERM=xterm-256color" govim bash -l
费尔南多·科雷亚添加
And Fernando Correia adds in the comments:
为了同时获得颜色支持和使
tmux
正常工作,我结合了两个示例:
To get both color support and make
tmux
work, I combined both examples:
docker exec -it my-container env TERM=xterm-256color script -q -c "/bin/bash" /dev/null
如 chepner 所述(较早的回答),由于 bash_prompt
是
As chepner commented (earlier answer), .bash_profile
is sourced (itis an interactive shell), since bash_prompt
is called by .bash_profile
.
但是 docker问题9299 说明了TERM
似乎没有设置立即,迫使用户使用以下命令打开另一个bash:
But docker issue 9299 illustrates that TERM
doesn't seem to be set right away, forcing the users to open another bash with:
docker exec -ti test env TERM=xterm-256color bash -l
您在问题8755 中也遇到了类似的颜色问题.
You have similar color issues with issue 8755.
docker exec -ti $CONTAINER_NAME tty
not a tty
当前解决方法是:
docker exec -ti `your_container_id` script -q -c "/bin/bash" /dev/null
两者都假设您首先有一个正在运行的容器,这在这里可能不方便.
Both are supposing you have a running container first, which might not be convenient here.
这篇关于Docker bash提示不显示颜色输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!