Docker+SSH+Vscode深度学习环境配置

Docker配置

下载docker image

docker pull ufoym/deepo:all-jupyter-py36-cu113

创建container

docker run -it -p 8022:22 --ipc=host --gpus=all --name="py36" -v /home/pan/coding:/root/coding ufoym/deepo:all-jupyter-py36-cu113 /bin/bash

进入docker

docker exec -it py36 /bin/bash

换源

cp /etc/apt/sources.list /etc/apt/sources.list.bk

cat < /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
EOF
# 清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# 腾讯源
pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple
# 豆瓣源
pip config set global.index-url http://pypi.douban.com/simple/
# 默认源
pip config unset global.index-url

SSH配置

安装 openssh-server

apt update
apt install -y vim openssh-server

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bk
mkdir /var/run/sshd
echo 'root:123' | chpasswd 
sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
echo "export VISIBLE=now" >> /etc/profile

SSH权限

vim /etc/ssh/sshd_config

PermitRootLogin yes #将PermitRootLogin的值改为yes(去掉前面的#号)

#重启激活SSH配置
service ssh restart

# 开机自动启动ssh命令
sudo systemctl enable ssh

# 关闭ssh开机自动启动命令
sudo systemctl disable ssh

# 单次开启ssh
sudo systemctl start ssh

# 单次关闭ssh
sudo systemctl stop ssh

# 设置好后重启系统
reboot

#查看ssh是否启动,看到Active: active (running)即表示成功
sudo systemctl status ssh

连接到远程docker

ssh [email protected] -p 8022

提交副本

docker commit -m "py36-ssh" eb16c6ffdb2b torch:py36_ssh

其中,-m 来指定提交的说明信息,跟我们使用的版本控制工具一样;-a 可以指定更新的用户信息;之后是用来创建镜像的容器的ID;最后指定目标镜像的仓库名和 tag 信息。创建成功后会返回这个镜像的 ID 信息。

安装总结

  1. Win10 docker内linux不支持nvidia,只支持DirectX调用GPU资源。https://docs.microsoft.com/zh-cn/virtualization/windowscontainers/deploy-containers/gpu-acceleration
  2. TensorFlow1.6版本以后不支持老款CPU指令集。
  3. VSCode的docker container插件连接容器,在容器内安装不了python调试插件。需要使用ssh进行连接。

你可能感兴趣的:(环境配置,python,deep,learning)