> CentOS > CentOS教程 >

CentOS7安装docker1.9.1

我这里安装Docker使用的是EPEL官方源,所以在上一篇文章我写了安装EPEL官方源的步骤。

1、安装:

yum -y install docker-io
查看Docker版本:

docker -v
显示结果如下:

Docker version 1.9.1, build ab77bde/1.9.1
2、启动Docker:

Docker作为服务启动

service docker start
3、查看已有镜像:

docker images
我这里没有显示没有镜像,需要下载镜像。

4、搜索并下载需要的CentOS镜像:

docker search centos
显示结果如下:

INDEX       NAME                                      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/centos                          The official build of CentOS.                   2329      [OK]      
docker.io   docker.io/ansible/centos7-ansible         Ansible on Centos7                              74                   [OK]
docker.io   docker.io/jdeathe/centos-ssh              CentOS-6 6.7 x86_64 / CentOS-7 7.2.1511 x8...   25                   [OK]
docker.io   docker.io/jdeathe/centos-ssh-apache-php   CentOS-6 6.7 x86_64 / Apache / PHP / PHP M...   17                   [OK]
docker.io   docker.io/nimmis/java-centos              This is docker images of CentOS 7 with dif...   12                   [OK]
docker.io   docker.io/million12/centos-supervisor     Base CentOS-7 with supervisord launcher, h...   11                   [OK]
docker.io   docker.io/consol/centos-xfce-vnc          Centos container with "headless" VNC sessi...   9                    [OK]
docker.io   docker.io/torusware/speedus-centos        Always updated official CentOS docker imag...   8                    [OK]
docker.io   docker.io/nickistre/centos-lamp           LAMP on centos setup                            4                    [OK]
docker.io   docker.io/centos/mariadb55-centos7                                                        3                    [OK]
docker.io   docker.io/nathonfowlie/centos-jre         Latest CentOS image with the JRE pre-insta...   3                    [OK]
docker.io   docker.io/consol/sakuli-centos-xfce       Sakuli end-2-end testing and monitoring co...   2                    [OK]
docker.io   docker.io/blacklabelops/centos            CentOS Base Image! Built and Updates Daily!     1                    [OK]
docker.io   docker.io/darksheer/centos                Base Centos Image -- Updated hourly             1                    [OK]
docker.io   docker.io/timhughes/centos                Centos with systemd installed and running       1                    [OK]
docker.io   docker.io/yajo/centos-epel                CentOS with EPEL and fully updated              1                    [OK]
docker.io   docker.io/ericuni/centos                  centos dev                                      0                    [OK]
docker.io   docker.io/grayzone/centos                 auto build for centos.                          0                    [OK]
docker.io   docker.io/grossws/centos                  CentOS 6 and 7 base images with gosu and l...   0                    [OK]
docker.io   docker.io/januswel/centos                 yum update-ed CentOS image                      0                    [OK]
docker.io   docker.io/jsmigel/centos-epel             Docker base image of CentOS w/ EPEL installed   0                    [OK]
docker.io   docker.io/kz8s/centos                     Official CentOS plus epel-release               0                    [OK]
docker.io   docker.io/labengine/centos                Centos image base                               0                    [OK]
docker.io   docker.io/repositoryjp/centos             Docker Image for CentOS.                        0                    [OK]
docker.io   docker.io/ustclug/centos                   USTC centos                                    0                    [OK]
我这里使用centos7-ansible镜像,需要下载镜像:

docker pull ansible/centos7-ansible
下载完成再看已经存在的镜像:

docker images
显示结果如下:

REPOSITORY                          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
docker.io/ansible/centos7-ansible   latest              8bfa335400c7        27 hours ago        454.3 MB
5、使用镜像创建Docker容器:

docker run -i -t 8bfa335400c7 /bin/bash
这里使用run命令,-i代表是交互的,-t代表是临时终端(伪终端),8bfa335400c7是镜像ID,即第四步中的IMAGE ID,使用/bin/bash,意思就是使用bash方式启动一个伪终端与容器进行交互,启动的时候会提示如下警告:

Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.
警告可以不用管,也可以去百度找解决办法,启动完毕之后就进入了docker容器。  退出容器:

exit
或者:

ctrl + d
退出之后可以查看所有使用过的容器:

docker ps -a
查看正在运行的容器:

docker ps
我这里因为启动的一个容器被关闭了,所以不使用-a命令时没有显示结果,使用-a命令会显示如下结果:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
20342f7db4a9        8bfa335400c7        "/bin/bash"         14 minutes ago      Exited (0) 4 minutes ago                       mad_archimedes
6、重新进入指定容器:

docker start 20342f7db4a9
使用start命令,后面的id值是上面查到的容器ID值(Container ID),启动之后使用如下命令进入:

docker attach 20342f7db4a9




(责任编辑:IT)