歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> CentOS7安裝docker1.9.1

CentOS7安裝docker1.9.1

日期:2017/3/6 9:47:43   编辑:學習Linux

CentOS7安裝docker1.9.1


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   AUTOMATEDdocker.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 SIZEdocker.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               NAMES20342f7db4a9        8bfa335400c7        "/bin/bash"         14 minutes ago      Exited (0) 4 minutes ago                       mad_archimedes

6、重新進入指定容器:

docker start 20342f7db4a9

使用start命令,後面的id值是上面查到的容器ID值(ContainerID),啟動之後使用如下命令進入:

docker attach 20342f7db4a9

http://xxxxxx/Linuxjc/1134236.html TechArticle

Copyright © Linux教程網 All Rights Reserved