跳至主要内容

Create a docker image for coding (2)

基本思路是基于alpine来安装一些软件,包括 zsh, tmux, vim 等。 ``` FROM alpine:latest RUN echo "start to build linux workspace" \ # Install Workspace related tools && apk add --update --no-cache git curl vim tmux zsh \ # Install VIM bundle && mkdir -p ~/.vim/bundle \ && git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim ``` 接着开始配置这些工具,像是 vim 和 tmux 最好使用 GitHub 上开放的配置文件,或者如果自己有偏好设置也行。我使用的就是自己定制的一些配置文件。 ``` COPY vimrc /root/.vimrc COPY tmux.conf /root/.tmux.conf ``` zsh 的配置就没有太多的花头,大名鼎鼎的 oh-my-zsh 足矣。 ``` RUN echo "then configure tools" \ # By default the login shell for root user is /bin/ash in alpine, replace with zsh && sed -i -e "s/bin\/ash/bin\/zsh/" /etc/passwd \ # Install oh-my-zsh and configure zsh && (sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" || true) \ && sed -i -- 's/robbyrussell/wezm+/g' /root/.zshrc ``` vim 的配置是基于 Vundle 的管理,所以先克隆了 Vundle.vim 再以命令行启动的方式来安装。tmux 的配置就直接用拷贝的文件无需特别修改。唯一的例外是由于我是在 Windows PC 上安装的,所以要替换掉 `^M` 也就是 DOS 风格的换行符。否则 linux 下的 vim 和 tmux 都无法加载这些配置。 ``` # Configure VIM, refer to https://github.com/VundleVim/Vundle.vim && sed -i -e "s/\r//g" /root/.vimrc /root/.tmux.conf \ && vim +PluginInstall +qall \ ``` 最后就是切换工作目录到 `/root` 并启动 `tmux`。 ``` WORKDIR /root ENTRYPOINT ["tmux"] ``` 然后用 `docker build -t jcb/coding:latest .` 来生成镜像文件,再 `docker run -it --rm jcb/coding:latest` 就可以用了。

评论