如果对您有帮助或者解决了您的问题, 就帮我点个赞或者评论关注支持吧, 您的鼓励是我写博客的最大支持, 感谢!
最近有搞机器学习的同学找我装环境,看着他各种环境配置.各种报错,最后看不下去的我让她用了Docker, 挽救了一下她的发量
1. 搜索镜像
搜索我们想要的anaconda镜像:
docker search anaconda
2. pull镜像
pull一个最高的
docker pull continuumio/anaconda3
3. 运行镜像 image->容器 docker run -i -t -p 12345:8888 continuumio/anaconda3 /bin/bash
参数解释
-i: 是 以交互模式运行容器,通常与 -t 同时使用;
-t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
-p: 指定端口映射,格式为:主机(宿主)端口:容器端口
然后可以看到进入了命令行
注意看目录是 / 现在已经是容器里了
4. 安装xgboost包 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple xgboost总安装失败的可以换成国内的镜像源, 现在是清华的源
5. 运行jupyter notebook
在容器中启动 jupyter notebook:
jupyter notebook --port 8888 --ip 0.0.0.0 --allow-root把前面的127.0.0.1:8888(容器的ip和端口)改为宿主机的ip和8888映射到宿主机的端口12345:
http://10.199.138.5:12345/?token=a6b3189e8f96802b6d193475f0e30908c3a2e16816e1a444然后在本地浏览器中打开即可:
如果对您有帮助或者解决了您的问题, 就帮我点个赞或者评论关注支持吧, 您的鼓励是我写博客的最大支持, 感谢! 以下为可选环节 6. 把当前容器打包为新的镜像当前我们对原始的 anaconda3 镜像做了一些改动:
安装了xgboost然后我们想把当前容器状态打包为新的镜像,这样以后我们就可以部署到其他地方了,而不用再安装xgboost等等。
使用 docker commit 命令来将容器打包为镜像:
root@hz-sjfx-test-199-138-5:~# docker commit --help Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] Create a new image from a container's changesOptions: -a, --author string Author (e.g., "John Hannibal Smith <hannibal@a-team.com>") -c, --change list Apply Dockerfile instruction to the created image --help Print usage -m, --message string Commit message -p, --pause Pause container during commit (default true)docker commit -a "nimendavid" -m "nimendavid's first docker image based on Anaconda3 with xgboost and lightgbm" dockername new_anaconda_xgboost
-a "nimendavid" 指的是作者
-m "nimendavid's......lightgbm" 指的是说明comment
dockername 指的是容器的短id,可以从命令行看出
new_anaconda_xgboost 指的是我们打包的新镜像的名称
7. 查看我们的新image docker image ls
8. 上传到 Docker Hub docker tag new_anaconda_xgboost:latest nimendavid/machine_learning:v0.1