Docker 安装 Python
1、查看可用的python版本
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
访问python镜像库地址:https://hub.docker.com/_/python?tab=tags
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
可以通过Sort by查看其他版本的python,默认是最新版本python:latest
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
2、用docker search python命令来查看可用版本
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
[root@localhost ~]# docker search python
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
3、拉取官方的镜像,标签为3.6
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
[root@localhost ~]# docker pull python:3.6
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
等待下载完成后,我们就可以在本地镜像列表里查到REPOSITORY为python, 标签为3.6的镜像。
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
4、查看镜像
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
[root@localhost ~]# docker images
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
5、创建python测试文件
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
[root@localhost ~]# mkdir -p ~/python
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
[root@localhost ~]# vim ~/python/test.py文章源自小柒博客-https://www.yangxingzhen.com/7210.html
#!/usr/bin/python print("Hello, World!");
6、启动python容器
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
[root@localhost ~]# docker run -v ~/python:/tmp -w /tmp python:3.6 python test.py
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
Hello, World!
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
命令说明:
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
-v ~/python:/tmp:将主机中当前目录下的python挂载到容器的/tmp。
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
-w /tmp:指定容器的/tmp目录为工作目录。
文章源自小柒博客-https://www.yangxingzhen.com/7210.html
python test.py:使用容器的python命令来执行工作目录中的test.py文件。文章源自小柒博客-https://www.yangxingzhen.com/7210.html
- 微信号
- 微信扫一扫加我!
-
- 微信公众号
- 微信扫一扫关注我!
-
评论