我如今作的是 Linux C++ 開發,但手頭上沒有 Linux 設備。目前的經常使用的方法有兩種:php
可是使用雲主機不方便,使用虛擬機對電腦有必定要求。還有第三種方法:Docker。html
本文介紹我使用 Docker 搭的一個 Linux C++ 編譯環境。如下是個人需求:git
經常使用的 Linux 系統有:CentOS 和 Ubuntu,我選擇了Ubuntu。github
From ubuntu:latest
因爲 Ubuntu 中包管理工具的源的服務器在國外,在國內使用 apt 安裝軟件,網速常常會很慢。先將源換成國內的源(阿里雲)。docker
RUN sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list && \ apt clean && \ apt update
build-essential
包含了編譯所須要的軟件,不過cmake
須要另外安裝。另外,Clion 須要rsync
來同步數據。shell
# 編譯工具 RUN apt install -y build-essential RUN apt install -y cmake RUN apt install -y gdb gdbserver RUN apt install -y rsync # Clion 須要 rsync 同步數據 RUN apt install -y vim # vim RUN apt install -y git # git
參考GitHub。不一樣 Ubuntu 版本的配置有差別。該倉庫中有其餘版本的配置信息。ubuntu
RUN apt install -y openssh-server RUN mkdir /var/run/sshd && \ mkdir /root/.ssh # 修改 root 的密碼爲 123456 RUN echo 'root:123456' | chpasswd RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config # SSH login fix. Otherwise user is kicked off after login RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config ENV NOTVISIBLE "in users profile" RUN echo "export VISIBLE=now" >> /etc/profile
參考把zsh放到docker裏這篇文章,將 Bash 換成 Zsh。vim
RUN apt install -y zsh RUN git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh \ && cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc \ && chsh -s /bin/zsh
還安裝了一些插件:segmentfault
# 參考 # https://segmentfault.com/a/1190000015283092 # https://juejin.im/post/5cf34558f265da1b80202d75 # 安裝 autojump 插件 RUN apt install -y autojump # 安裝 zsh-syntax-highlighting 插件 RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \ ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting # 安裝 zsh-autosuggestions 插件 RUN git clone https://github.com/zsh-users/zsh-autosuggestions \ ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions # 安裝 git-open 插件 RUN git clone https://github.com/paulirish/git-open.git \ ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/git-open RUN sed -ri 's/^plugins=.*/plugins=(git autojump zsh-syntax-highlighting zsh-autosuggestions git-open)/' ~/.zshrc
在個人GitHub上有Dockerfile文件。服務器