Docker bash prompt does not display color output

后端 未结 5 1257
闹比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:32

    Based on @VonC's answer I adding the following to my Dockerfile (which allows me to run the container without typing the environment variables on the cli every time) :

    ENV TERM xterm-256color
    #... more stuff
    CMD ["bash", "-l"]
    

    and sure enough it works with:

    docker run -it my-image:tag
    

    For tmux to work with color, in my ~/.tmux.conf I need:

    set -g default-terminal "screen-256color"
    

    and for utf8 support in tmux, in my ~/.bashrc:

    alias tmux='tmux -u'
    

    My Dockerfile:

    FROM fedora:26
    ENV TERM xterm-256color
    RUN dnf upgrade -y && \
        dnf install golang tmux git vim -y && \
        mkdir -p /app/go/{bin,pkg,src} && \
        echo 'export GOPATH=/app/go' >> $HOME/.bashrc && \
        echo 'export PATH=$PATH:$GOPATH/bin' >> $HOME/.bashrc && \
        mkdir -p ~/.vim/autoload ~/.vim/bundle && \
        curl -LSso ~/.vim/autoload/pathogen.vim \
            https://tpo.pe/pathogen.vim && \
        git clone https://github.com/farazdagi/vim-go-ide.git \
            ~/.vim_go_runtime && \
        bash ~/.vim_go_runtime/bin/install && \
        echo "alias govim='vim -u ~/.vimrc.go'" >> ~/.bashrc && \
        echo "alias tmux='tmux -u'" >> ~/.bashrc && \
        echo 'set -g default-terminal "screen-256color"' >> ~/.tmux.conf
    
    CMD ["bash", "-l"]
    

    The Dockerfile builds an image based off Fedora 26, updates it, installs a few packages (git, vim, golang and tmux),installs the pathogen plugin for vim, then it installs a git repo from here vim-go-ide and finally does a few tweaks to a few config files to get color and utf8 working fine. Just need to add persistent storage, probably mounted under /app/go.

    If you have an image with all the development tools already installed, just make a Dockerfile with ENV statement and add the commands to modify the config files in a RUN statement without the installation commands and use your base image in the FROM statement. I prefer this solution because I'm lazy and (besides the initial setup) it saves typing when you want to run the image.

    Using vim and plugins within tmux

提交回复
热议问题