博客
关于我
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/

你可能感兴趣的文章
NT symbols are incorrect, please fix symbols
查看>>
ntelliJ IDEA 报错:找不到包或者找不到符号
查看>>
NTFS文件权限管理实战
查看>>
ntko web firefox跨浏览器插件_深度比较:2019年6个最好的跨浏览器测试工具
查看>>
ntko文件存取错误_苹果推送 macOS 10.15.4:iCloud 云盘文件夹共享终于来了
查看>>
ntp server 用法小结
查看>>
ntpdate 通过外网同步时间
查看>>
ntpdate同步配置文件调整详解
查看>>
NTPD使用/etc/ntp.conf配置时钟同步详解
查看>>
NTP及Chrony时间同步服务设置
查看>>
NTP服务器
查看>>
NTP配置
查看>>
NUC1077 Humble Numbers【数学计算+打表】
查看>>
NuGet Gallery 开源项目快速入门指南
查看>>
NuGet(微软.NET开发平台的软件包管理工具)在VisualStudio中的安装的使用
查看>>
nuget.org 无法加载源 https://api.nuget.org/v3/index.json 的服务索引
查看>>
Nuget~管理自己的包包
查看>>
NuGet学习笔记001---了解使用NuGet给net快速获取引用
查看>>
nullnullHuge Pages
查看>>
NullPointerException Cannot invoke setSkipOutputConversion(boolean) because functionToInvoke is null
查看>>