Docker bash prompt does not display color output

后端 未结 5 1233
闹比i
闹比i 2020-12-23 17:10

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

5条回答
  •  再見小時候
    2020-12-23 17:41

    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.

提交回复
热议问题