美文网首页
Docker 配环境(ubuntu+python3.6+pip)

Docker 配环境(ubuntu+python3.6+pip)

作者: V_6619 | 来源:发表于2021-10-28 22:08 被阅读0次

拉取ubuntu20.04镜像

docker pull ubuntu:20.04
docker run -itd ubuntu:20.04
docker ps -a

看到如图


image.png
docker attach 【容器id】

安装python3.6

可根据自己的需要进行调整

apt-get update
apt-get install software-properties-common

然后应该是有了python3.8版本,可以用下述命令去查

python3 -V

安装python3.6【可以根据自己的python版本进行调整】

add-apt-repository ppa:deadsnakes/ppa
apt-get update
apt-get install python3.6

可以进去/usr/bin目录查看自己是否安装了3.6,这时候应该是已经有了3.6

rm python3
ln -s python3.6m python3

然后用下述命令可以看到已经是3.6版本

python3 -V

安装pip

apt-get install python3-pip

用下述命令可以查看是否安装成功

pip -V

看到如下证明已经安装成功


image.png

如果需要使用gpu,在启动容器时加上 --gpus all

docker run -itd --name 容器名字  --gpus all -p 服务器端口号:容器端口号 镜像名字

如果需要将自己的镜像迁移出来

docker save -o ubuntu_20_04.tar ubuntu:20.04:将镜像ubuntu:20.04导出到本地文件
docker load -i ubuntu_20_04.tar:将镜像ubuntu:20.04从本地文件ubuntu_20_04.tar中加载出来

将容器打包成镜像

docker commit 【容器id】 【新镜像名称】

pip配置国内镜像

mkdir ~/.pip
vim ~/.pip/pip.conf

写入

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

检查是否成功:

pip3 config list

得到结果


image.png

相关文章

网友评论

      本文标题:Docker 配环境(ubuntu+python3.6+pip)

      本文链接:https://www.haomeiwen.com/subject/rolbaltx.html