当前位置: 首页 > Linux

使用Docker搭建LinuxC++编译环境

时间:2023-04-06 02:25:42 Linux

我是做LinuxC++开发的,但是手头没有Linux设备。目前常用的方式有两种:云主机和虚拟机。但是使用云主机不方便,使用虚拟机对电脑也有一定的要求。还有第三种方法:Docker。本文介绍我使用Docker搭建的一个LinuxC++编译环境。以下是我的要求:可远程调试的C++编译环境;远程连接工具:ssh;版本控制工具:git;编辑器:Vim;易于使用的外壳:zsh和插件。系统中常用的Linux系统有:CentOS和Ubuntu,我选择的是Ubuntu。来自ubuntu:latest换源由于Ubuntu中包管理工具的源服务器在国外,而在国内使用apt安装软件,网速往往很慢。先把源换成国内的源(阿里云)。RUNsed-is@/archive.ubuntu.com/@/mirrors.aliyun.com/@g/etc/apt/sources.list&&\aptclean&&\aptupdateC++编译环境build-essential包含了需要的软件compilation,但是cmake需要单独安装。另外,Clion需要rsync来同步数据。#编译工具RUNaptinstall-ybuild-essentialRUNaptinstall-ycmakeRUNaptinstall-ygdbgdbserverRUNaptinstall-yrsync#Clion需要rsync同步数据RUNaptinstall-yvim#vimRUNaptinstall-ygit#gitssh参考知乎不同Ubuntu版本的配置有所不同。此存储库中有其他版本的配置信息。RUNaptinstall-yopenssh-serverRUNmkdir/var/run/sshd&&\mkdir/root/.ssh#更改root密码为123456RUNecho'root:123456'|chpasswdRUNsed-ri's/^#?PermitRootLogin\s+.*/PermitRootLoginyes/'/etc/ssh/sshd_config#SSH登录修复。否则用户登录后被踢掉RUNsed-ri's/UsePAMyes/#UsePAMyes/g'/etc/ssh/sshd_configENVNOTVISIBLE"inusersprofile"RUNecho"exportVISIBLE=now">>/etc/profileZsh参考将zsh放入docker的文章,并用Zsh替换Bash。运行aptinstall-yzsh运行gitclonehttps://github.com/robbyrussell/oh-my-zsh.git~/.oh-my-zsh\&&cp~/.oh-my-zsh/templates/zshrc。zsh-template~/.zshrc\&&chsh-s/bin/zsh还安装了一些插件:#参考#https://segmentfault.com/a/1190000015283092#https://juejin.im/post/5cf34558f265da1b80202d75#安装autojump插件RUNaptinstall-yautojump#安装zsh-syntax-highlighting插件RUNgitclonehttps://github.com/zsh-users/zsh-syntax-highlighting.git\${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting#安装zsh-autosuggestions插件RUNgitclonehttps://github.com/zsh-users/zsh-autosuggestions\${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions#安装git-open插件RUNgitclonehttps://github.com/paulirish/git-open.git\${ZSH_CUSTOM:-~/.oh-my-zsh/custom/plugins/git-openRUNsed-ri's/^plugins=.*/plugins=(gitautojumpzsh-syntax-highlightingzsh-autosuggestionsgit-open)/'~/.zshrcDockerfile我的GitHub上有Dockerfile。