Mac m1上使用docker搭建C++开发调试环境

说明

因为mac上虚拟机都不太好用,有些还收费,故使用docker来搭建虚拟机。况且我的Mac是m1芯片,用的是arm架构,虚拟机更是少。

搭建本机与虚拟机互通

mac上docker与linux不同,mac上实际上内部是建了个linux的虚拟机来实现。mac上本机和虚拟机互通使用docker-connect

brew install wenjunxiao/brew/docker-connector


docker network ls --filter driver=bridge --format "{{.ID}}" | xargs docker network inspect --format "route {{range .IPAM.Config}}{{.Subnet}}{{end}}" >> /opt/homebrew/etc/docker-connector.conf
For the first time, you can add all the bridge networks of docker to the routing table by the following command:
  docker network ls --filter driver=bridge --format "{{.ID}}" | xargs docker network inspect --format "route {{range .IPAM.Config}}{{.Subnet}}{{end}}" >> /opt/homebrew/etc/docker-connector.conf
Or add the route of network you want to access to following config file at any time:
  /opt/homebrew/etc/docker-connector.conf
Route format is `route subnet`, such as:
  route 172.17.0.0/16
The route modification will take effect immediately without restarting the service.
You can also expose you docker container to other by follow settings in /opt/homebrew/etc/docker-connector.conf:
  expose 0.0.0.0:2512
  route 172.17.0.0/16 expose
Let the two subnets access each other through iptables:
  iptables 172.17.0.0+172.18.0.0

To start wenjunxiao/brew/docker-connector now and restart at startup:
  sudo brew services start wenjunxiao/brew/docker-connector
Or, if you don't want/need a background service you can just run:
  sudo docker-connector -config /opt/homebrew/etc/docker-connector.conf
docker run -it -d --restart always --net host --cap-add NET_ADMIN --name mac-docker-connector wenjunxiao/mac-docker-connector

搭建centos8容器开发环境

docker pull centos:8

docker network create --subnet=172.16.160.0/24 bridge_for_dev

docker run -itd --privileged=true --restart=always --name centos-dev --hostname centos-dev --net bridge_for_dev --ip 172.16.160.66 centos:8  /usr/sbin/init

以上/usr/sbin/init启动,便可以使用systemclt命令

下面进入容器,开始一系列环境的安装

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*

sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

yum clean all
yum makecache
echo "export LC_ALL=C.UTF8" >> /etc/profile
source /etc/profile

sudo

yum install sudo -y

openssh

yum install openssh-server -y

sudo systemctl enable sshd
systemctl start sshd

net

yum install net-tools -y
yum install -y iputils

password

yum install passwd -y

gcc

yum install gcc gcc-c++ gdb -y
yum install automake autoconf libtool make -y
yum install ncurses-devel perl -y
yum install cmake -y
yum install python3 -y

man

yum install man -y
yum install man-pages -y

注意

本来想使用docker建一个x86架构的远程调试环境,但是无论是使用vscode还是使用clion,都无法远程debug,想着估计是系统架构不同,内部又是用qume模拟器来做了一次指令的翻译,过程中可能导致一些权限的降级或者功能的缺失吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值