博客
关于我
docker(3)快速搭建centos7-python3.6环境
阅读量:433 次
发布时间:2019-03-06

本文共 1370 字,大约阅读时间需要 4 分钟。

Docker环境搭建指南

前言

搭建Python环境时总是觉得麻烦?重新搭建Python3.6环境时总是忘不了设置环境变量?每次安装完pip后又提示"pip不是内部或外部命令",再次提示"pip: command not found",让人感到抓耳挠腮。从今天开始学习Docker,让环境问题迎刃而解!


Docker搜索镜像

使用docker search命令从Docker Hub搜索镜像。例如,搜索基于CentOS7环境安装的Python3.6版本:

docker search python

搜索结果如下:

镜像仓库 描述 星期星数 官方镜像 自动化构建
python Python解释性脚本语言 5776 [OK] [OK]
pypy PyPy快速替代Python实现 262 [OK] [OK]
centos/python-36-centos7 安装Python3.6环境 30 [OK] [OK]

通过tags标签筛选镜像版本,例如选择Python3.8版本:

docker search python:3.8

下载镜像

选择了镜像centos/python-36-centos7后,执行下载命令:

docker pull centos/python-36-centos7

下载完成后,可以通过docker images查看本地镜像:

docker images

安装其他Python版本

如果需要安装Python3.7或3.8版本,同样可以通过搜索镜像并下载对应的版本:

docker search python:3.7docker pull centos/python-37-centos7

运行交互式容器

启动一个交互式容器,进入Python环境:

docker run -i -t centos/python-36-centos7 /bin/bash

运行结果如下:

root@25743368a66d:/opt/webapp# pythonPython 3.6.9 (default, Nov 11 2019, 11:24:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> print("hello")hello>>> exit()

后台模式启动

如果不需要交互式终端,可以通过-d参数启动后台容器:

docker run -d centos/python-36-centos7 /bin/echo "hello world"

停止容器

停止运行的容器可以通过docker stop命令:

docker stop CONTAINER_ID

启动容器

重新启动容器:

docker start CONTAINER_ID

删除容器

删除不需要的容器时,需先停止运行:

docker stop CONTAINER_NAMEdocker rm CONTAINER_NAME

删除已停止运行的容器

清理所有停止的容器:

docker container prune

通过以上命令可以轻松管理Docker容器,解决环境搭建问题。

转载地址:http://knuyz.baihongyu.com/

你可能感兴趣的文章
npm install 报错 fatal: unable to connect to github.com 的解决方法
查看>>
npm install 报错 no such file or directory 的解决方法
查看>>
npm install报错,证书验证失败unable to get local issuer certificate
查看>>
npm install无法生成node_modules的解决方法
查看>>
npm install的--save和--save-dev使用说明
查看>>
npm node pm2相关问题
查看>>
npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
查看>>
npm run build报Cannot find module错误的解决方法
查看>>
npm run build部署到云服务器中的Nginx(图文配置)
查看>>
npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
查看>>
npm scripts 使用指南
查看>>
npm should be run outside of the node repl, in your normal shell
查看>>
npm start运行了什么
查看>>
npm WARN deprecated core-js@2.6.12 core-js@<3.3 is no longer maintained and not recommended for usa
查看>>
npm 下载依赖慢的解决方案(亲测有效)
查看>>
npm 安装依赖过程中报错:Error: Can‘t find Python executable “python“, you can set the PYTHON env variable
查看>>
npm.taobao.org 淘宝 npm 镜像证书过期?这样解决!
查看>>
npm—小记
查看>>
npm介绍以及常用命令
查看>>
NPM使用前设置和升级
查看>>