【docker】基于docker的python虚拟环境搭建

一、安装dokcer:

官网下载docker镜像并安装;

二、查找centos镜像:

macbook:portal zhaoxueyong$ docker search centos
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                             The official build of CentOS.                   3579      [OK]       
ansible/centos7-ansible            Ansible on Centos7                              100                  [OK]
jdeathe/centos-ssh                 CentOS-6 6.9 x86_64 / CentOS-7 7.3.1611 x8...   81                   [OK]
tutum/centos                       Simple CentOS docker image with SSH access      33                   
imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              30                   [OK]
gluster/gluster-centos             Official GlusterFS Image [ CentOS-7 +  Glu...   19                   [OK]
kinogmt/centos-ssh                 CentOS with SSH                                 16                   [OK]
centos/php-56-centos7              PHP 5.6 platform for building and running ...   8                    
guyton/centos6                     From official centos6 container with full ...   7                    [OK]
openshift/base-centos7             A Centos7 derived base image for Source-To...   7                    
openshift/mysql-55-centos7         DEPRECATED: A Centos7 based MySQL v5.5 ima...   6                    
openshift/ruby-20-centos7          DEPRECATED: A Centos7 based Ruby v2.0 imag...   3                    
darksheer/centos                   Base Centos Image -- Updated hourly             3                    [OK]
...

三、下载centos镜像:

macbook:portal zhaoxueyong$ docker pull centos
Using default tag: latest
latest: Pulling from library/centos
74f0853ba93b: Pull complete 
Digest: sha256:26f74cefad82967f97f3eeeef88c1b6262f9b42bc96f2ad61d6f3fdf544759b8
Status: Downloaded newer image for centos:latest

四、启动容器:

macbook:portal zhaoxueyong$ docker run -t -i --name=python-env centos
[root@00183564ac22 /]#

五、容器中部署环境:

...

六、退出容器:

Dependency Installed:
  gpm-libs.x86_64 0:1.20.7-5.el7                  groff-base.x86_64 0:1.22.2-8.el7         perl.x86_64 4:5.16.3-291.el7                 perl-Carp.noarch 0:1.26-244.el7            
  perl-Encode.x86_64 0:2.51-7.el7                 perl-Exporter.noarch 0:5.68-3.el7        perl-File-Path.noarch 0:2.09-2.el7           perl-File-Temp.noarch 0:0.23.01-3.el7      
  perl-Filter.x86_64 0:1.49-3.el7                 perl-Getopt-Long.noarch 0:2.40-2.el7     perl-HTTP-Tiny.noarch 0:0.033-3.el7          perl-PathTools.x86_64 0:3.40-5.el7         
  perl-Pod-Escapes.noarch 1:1.04-291.el7          perl-Pod-Perldoc.noarch 0:3.20-4.el7     perl-Pod-Simple.noarch 1:3.28-4.el7          perl-Pod-Usage.noarch 0:1.63-3.el7         
  perl-Scalar-List-Utils.x86_64 0:1.27-248.el7    perl-Socket.x86_64 0:2.010-4.el7         perl-Storable.x86_64 0:2.45-3.el7            perl-Text-ParseWords.noarch 0:3.29-4.el7   
  perl-Time-HiRes.x86_64 4:1.9725-3.el7           perl-Time-Local.noarch 0:1.2300-2.el7    perl-constant.noarch 0:1.27-2.el7            perl-libs.x86_64 4:5.16.3-291.el7          
  perl-macros.x86_64 4:5.16.3-291.el7             perl-parent.noarch 1:0.225-244.el7       perl-podlators.noarch 0:2.5.1-3.el7          perl-threads.x86_64 0:1.87-4.el7           
  perl-threads-shared.x86_64 0:1.43-6.el7         vim-common.x86_64 2:7.4.160-1.el7_3.1    vim-filesystem.x86_64 2:7.4.160-1.el7_3.1    which.x86_64 0:2.20-7.el7                  

Complete!
[root@00183564ac22 /]# ls
anaconda-post.log  bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@00183564ac22 /]# exit
exit

七、重新进入容器:

macbook:portal zhaoxueyong$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                          PORTS               NAMES
00183564ac22        centos              "/bin/bash"         15 minutes ago      Exited (0) About a minute ago                       python-env
cea3afc41538        hello-world         "/hello"            37 hours ago        Exited (0) 37 hours ago                             competent_shockley
macbook:portal zhaoxueyong$ docker start 00183564ac22
00183564ac22
macbook:portal zhaoxueyong$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                    PORTS               NAMES
00183564ac22        centos              "/bin/bash"         19 minutes ago      Up 3 seconds                                  python-env
cea3afc41538        hello-world         "/hello"            38 hours ago        Exited (0) 38 hours ago                       competent_shockley
macbook:portal zhaoxueyong$ docker attach 00183564ac22
[root@00183564ac22 /]#

推荐阅读更多精彩内容

  • 最近研究了几天docker的快速部署,感觉很有新意,非常轻量级和方便,打算在公司推广一下,解放运维,省得每次部署一...
    Helen_Cat阅读 952评论 0 4
  • 前文讲到 Git 的基础命令,这里谈一下 Git 的分支管理。 Git 的每一次提交都是为当前所有文件创建一个快照...
    tao_tao阅读 206评论 0 5
  • 有些东西在旁人看来可能一文不值,但对有些人来说却非常珍贵。 那东西可能已经用了很久了,什么时候扔掉都不会觉得可惜,...
    番茄陷丸子阅读 135评论 0 1
  • 踏出那片不曾觉得有归属的校园,步入喧嚣的楼宇之间。翻着满是笑容的相册,想着带着酸涩笑在学校的拱桥上,伴着漫天...
    不安心动阅读 469评论 0 0