Docker入門のCentOs 6.5 Dockerインストールおよびコンテナ出力helloworld

18574 ワード

  • 1.Docker
  • のインストール
    yum install -y docker-io

    エラーの実行:
    [root@server1 ~]# yum install -y docker-io
    Loaded plugins: fastestmirror
    Determining fastest mirrors
     * base: mirrors.btte.net
     * extras: mirrors.btte.net
     * updates: mirrors.btte.net
    base                                  | 3.7 kB     00:00     
    extras                                | 3.4 kB     00:00     
    updates                               | 3.4 kB     00:00     
    updates/primary_db                    | 1.9 MB     00:02     
    Setting up Install Process
    No package docker-io available.
    Error: Nothing to do

    理由:私が使っているCentOs 6.5 epelサードパーティのソフトウェアライブラリを更新して再インストールする必要がある
    解決:
    yum install epel-release

    再インストールOK、バージョン1.7.1:
    Dependencies Resolved
    
    ==============================================================================
     Package                       Arch      Version            Repository   Size
    ==============================================================================
    Installing:
     docker-io                     x86_64    1.7.1-2.el6        epel        4.6 M
    Installing for dependencies:
     bridge-utils                  x86_64    1.2-10.el6         base         30 k
     libcgroup                     x86_64    0.40.rc1-23.el6    base        131 k
     lua-alt-getopt                noarch    0.7.0-1.el6        epel        6.9 k
     lua-filesystem                x86_64    1.4.2-1.el6        epel         24 k
     lua-lxc                       x86_64    1.0.9-1.el6        epel         16 k
     lxc                           x86_64    1.0.9-1.el6        epel        122 k
     lxc-libs                      x86_64    1.0.9-1.el6        epel        257 k
     rsync                         x86_64    3.0.6-12.el6       base        335 k
    
    Transaction Summary
    ==============================================================================
  • 2.Docker
  • の起動
    /etc/init.d/docker start    service docker start

    ステータスdockerの起動に失敗しました:
    [root@server1 ~]# service docker status
    docker dead but pid file exists

    理由を表示:
    [root@server1 ~]# tail -100 /var/log/docker 
    
    Thu Jul 6 09:37:50 EDT 2017
    time="2017-07-06T09:37:50.197159063-04:00" level=warning msg="You are running linux kernel version 2.6.32-431.el6.x86_64, which might be unstable running docker. Please upgrade your kernel to 3.10.0." time="2017-07-06T09:37:50.214354587-04:00" level=info msg="Listening for HTTP on unix (/var/run/docker.sock)" /usr/bin/docker: relocation error: /usr/bin/docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference
    Thu Jul 6 09:39:50 EDT 2017
    time="2017-07-06T09:39:50.458100631-04:00" level=warning msg="You are running linux kernel version 2.6.32-431.el6.x86_64, which might be unstable running docker. Please upgrade your kernel to 3.10.0." /usr/bin/docker: relocation error: /usr/bin/docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference

    解決:エラーに基づいて次の文を実行します.
    #       ,  yum-config-manager yum-utils  
    yum -y install yum-utils
    yum-config-manager --enable public_ol6_latest
    yum install -y device-mapper-event-libs
    

    再起動:
    [root@server1 ~]# service docker start
    Starting docker:                                       [  OK  ]
    [root@server1 ~]# service docker status
    docker (pid  1530) is running...
    
  • 3.ミラーのダウンロード:
  • CentOSミラーの表示:
    [root@server1 ~]# docker search centos
    NAME                                   DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
    centos                                 The official build of CentOS.                   3450      [OK]       
    jdeathe/centos-ssh                     CentOS-6 6.9 x86_64 / CentOS-7 7.3.1611 x8...   75                   [OK]
    consol/centos-xfce-vnc                 Centos container with "headless" VNC sessi...   27                   [OK]
    nimmis/java-centos                     This is docker images of CentOS 7 with dif...   26                   [OK]
    gluster/gluster-centos                 Official GlusterFS Image [ CentOS-7 +  Glu...   19                   [OK]
    egyptianbman/docker-centos-nginx-php   A simple and highly configurable docker co...   9                    [OK]
    torusware/speedus-centos               Always updated official CentOS docker imag...   8                    [OK]
    nathonfowlie/centos-jre                Latest CentOS image with the JRE pre-insta...   6                    [OK]
    centos/mariadb55-centos7                                                               5                    [OK]
    darksheer/centos                       Base Centos Image -- Updated hourly             3                    [OK]
    harisekhon/centos-java                 Java on CentOS (OpenJDK, tags jre/jdk7-8)       2                    [OK]
    harisekhon/centos-scala                Scala + CentOS (OpenJDK tags 2.10-jre7 - 2...   2                    [OK]
    blacklabelops/centos                   CentOS Base Image! Built and Updates Daily!     1                    [OK]
    timhughes/centos                       Centos with systemd installed and running       1                    [OK]
    vorakl/centos                          CentOS7, EPEL, tools. Updated/Tested daily!     1                    [OK]
    freenas/centos                         Simple CentOS Linux interactive container       1                    [OK]
    sgfinans/docker-centos                 CentOS with a running sshd and Docker           1                    [OK]
    grossws/centos                         CentOS 6 and 7 base images with gosu and l...   0                    [OK]
    repositoryjp/centos                    Docker Image for CentOS.                        0                    [OK]
    smartentry/centos                      centos with smartentry                          0                    [OK]
    vcatechnology/centos                   A CentOS Image which is updated daily           0                    [OK]
    januswel/centos                        yum update-ed CentOS image                      0                    [OK]
    aguamala/centos                        CentOS base image                               0                    [OK]
    dmglab/centos                          CentOS with some extras - This is for the ...   0                    [OK]
    kz8s/centos                            Official CentOS plus epel-release               0                    [OK]
    
    

    ミラーのプル:
    #docker    github  , pull  centos   
    docker pull centos

    ローカルマシン上のミラーの表示:docker images
    
    [root@server1 ~]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    centos              latest              72a210db1424        17 hours ago        192.5 MB
    
  • 4.ミラー
  • の使用
    dockerミラーでhelloworld docker run centos/bin/echo'hello world'docker run–name lijie-it centos/bin/bashを実行-iコンテナ端末は開いたまま-t開いた偽端末は標準入力にバインドされます
    [root@server1 ~]# docker run centos /bin/echo 'hello world'
    hello world
    
    [root@server1 ~]# docker run --name lijie -it centos /bin/bash
    [root@f6fedfb668c5 /]# 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@f6fedfb668c5 /]# echo "hello world"
    hello world
    [root@f6fedfb668c5 /]# exit
    exit
    [root@server1 ~]# 

    5.dockerが実行するプロセスを表示する:docker ps-a
    [root@server1 ~]# docker ps -a
    CONTAINER ID        IMAGE       COMMAND                CREATED              STATUS                          PORTS   NAMES
    f6fedfb668c5        centos      "/bin/bash"            About a minute ago   Exited (0) 29 seconds ago               lijie               
    23fc0bfb2cb6        centos      "/bin/echo 'hello wo   About a minute ago   Exited (0) About a minute ago           gloomy_curie 
    

    6.終了済みコンテナを起動します.
    docker start   id

    7.バックグラウンド運転容器:docker run-d–name backnginx nginx
    [root@server1 ~]# docker run -d --name backnginx  nginx
    Unable to find image 'nginx:latest' locally   #         ,docker   pull  nginx  
    latest: Pulling from nginx
    1943e5bcdc2e: Pull complete 
    6391f4389286: Pull complete 
    687fb83caec2: Pull complete 
    e3987e5b38d4: Pull complete 
    a3d9ed6d7e57: Pull complete 
    a36537d4476c: Pull complete 
    8601894c2243: Pull complete 
    427673d842a6: Pull complete 
    bccedf258637: Pull complete 
    11409c2f6e71: Pull complete 
    Digest: sha256:87e4b276c1b87ab7a1de9df434aba1d2447bc136d767a38c56b91b7166d9bfce
    Status: Downloaded newer image for nginx:latest
    58f75c29cbf13dcfd5492553d0f00c1b8eb6bbf3922ddf6b7fa54c7dc08179f4

    8.nginxコンテナを表示するには:
    [root@server1 ~]# docker ps -a
    CONTAINER ID        IMAGE     COMMAND                CREATED             STATUS                       PORTS   NAMES
    58f75c29cbf1        nginx     "nginx -g 'daemon of   42 seconds ago      Up 41 seconds                80/tcp  backnginx           
    f6fedfb668c5        centos    "/bin/bash"            5 minutes ago       Exited (137) 3 minutes ago           lijie               
    23fc0bfb2cb6        centos    "/bin/echo 'hello wo   5 minutes ago       Exited (0) 5 minutes ago             gloomy_curie
    

    9.容器の停止:
    docker stop   id

    10.コンテナを削除するには:
    docker rm   id

    11.コンテナミラーを削除するには:
    docker rmi   id

    12.実行中のコンテナの強制削除:
    docker rm -f   id

    13.コンテナに入ります.
    #  docker      pid
    #docker inspect --format "{{.State.Pid}}"        ID
    
    [root@server1 ~]# docker inspect --format "{{.State.Pid}}" backnginx
    3410
    
    [root@server1 ~]# nsenter --target 3410 --mount --uts --ipc --net --pid
    mesg: ttyname failed: No such file or directory
    root@3940205a9fd4:/# ls
    bin  boot  dev  etc  home  lib  lib32  lib64  libx32  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
    

    14.nsenterコマンドがなければyumをインストールできます.
    [root@server1 ~]# yum install -y util-linux