Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

linux - Docker Bash prompt does not display color output

I use the 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.

Bash Prompt Image

My bash_profile and bash_prompt files.

question from:https://stackoverflow.com/questions/33493456/docker-bash-prompt-does-not-display-color-output

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

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

As chepner commented (earlier answer), .bash_profile is sourced (itis an interactive shell), since bash_prompt is called by .bash_profile.

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

You have similar color issues with issue 8755.

To illustrate/reproduce the problem:

docker exec -ti $CONTAINER_NAME tty
not a tty

The current workaround is :

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...