首先你的需要准备:docker/Linux、Pycharm。以下我只说怎么在docker中配置。
1.Pcharm连接Linux: 直接参考连接Linux远程环境的配置方法:Pycharm配置远程环境(Linux)。
2.给docker设置好sshd服务: 因为上一步里面需要用账号去连接Linux,这里首先要解决的一个问题就是给docker安装sshd的服务,这里我推荐参考:ssh连接docker。
但是这个有一个问题要解决,如果你直接docker run
一个容器Linux里面是不能够使用systemctl,报错信息如下:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
解决这个问题需要做两个操作:
1.entrypoint指向/sbin/init
2.容器设置privileged: true
这里第1步启动的入口指向就是启动保持进程的那个参数,第2步的privileged在docker启动的时候输入--privileged
参数。docker开启privileged
docker run -t -i --name test --privileged centos:latest /sbin/init
到这里就已经完成了连接docker里解释器的的基本条件,如果还需要做虚拟环境的话:
pip3 install virtualenv # 安装virtualenv
virtualenv -p python3 test_ve # 创建一个虚拟环境 默认python
source test_ve/bin/activate # 进入虚拟环境
deactivate # 退出虚拟环境