为了开发使用方便,搭建一套可直接运行的pytorch + jupyter的docker
一,下载pytorch docker
docker pull pytorch/pytorch:1.6.0-cuda10.1-cudnn7-runtime
二,安装 Jupyter
1,运行 pytorch 容器
nvidia-docker run -it --network=host -d pytorch/pytorch:1.6.0-cuda10.1-cudnn7-runtime
2,进入容器
docker exec -it xxxx(容器ID)
3,安装jupyter
pip install jupyter
4,生成配置文件
jupyter notebook --generate-config
如果使用root用户生成的配置文件路径为
/root/.jupyter/jupyter_notebook_config.py
5,生成密码
jupyter notebook password
密码会直接写入搭配配置文件中
Enter password:
Verify password:
[NotebookPasswordApp] Wrote hashed password to /root/.jupyter/jupyter_notebook_config.json
6,启动程序
jupyter notebook --ip=0.0.0.0 --no-browser --allow-root
注:也可以通过修改配置文件配置地址及端口号
/root/.jupyter/jupyter_notebook_config.json
{
"NotebookApp": {
"password": "xxxxx",
"ip": "0.0.0.0",
"port": 8888
}
}
jupyter notebook --no-browser --allow-root
7,保存docker镜像
docker commit xxxx(容器ID) pytorch/pytorch_jupyter:1.6.0-cuda10.1-cudnn7-runtime
之后可以直接运行使用保存的docker镜像。