zoukankan      html  css  js  c++  java
  • 一、docker安装CentOS7

    一、安装步骤

    前提条件

    Docker运行在CentOS7上,要求系统64位、系统内核版本为3.10以上。

    Docker是一个进程,一启动就两个进程,一个服务,一个守护进程。占用资源就非常少,启动速度非常

    1,root账户登录,查看内核版本如下

    [root@localhost ~]# uname -a
    Linux localhost.qgc 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

    2、卸载旧版本(如果安装过旧版本的话)

    $ sudo yum remove docker  docker-common docker-selinux docker-engine

    3、安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

    $ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

    4、加软件源

    [liu@localhost ~]$ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    sudo: yum-config-manager: command not found -----(表示依赖环境没有安装)

    5、可以查看所有仓库中所有docker版本,并选择特定版本安装 (可选)

    $ yum list docker-ce --showduplicates | sort -r

    6:设置远程仓库

    $sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    
    执行结果: Loaded plugins: fastestmirror, langpacks adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo

    7、更新缓存

    1. yum makecache fast

    8、安装docker

    $ sudo yum install docker-ce
    
    执行结果: Loaded plugins: fastestmirror, langpacks docker
    -ce-stable | 2.9 kB 00:00:00 docker-ce-stable/x86_64/primary_db | 4.8 kB 00:00:00 Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package docker-ce.x86_64 0:17.03.1.ce-1.el7.centos will be installed --> Processing Dependency: docker-ce-selinux >= 17.03.1.ce-1.el7.centos for package: docker-ce-17.03.1.ce-1.el7.centos.x86_64 --> Processing Dependency: libcgroup for package: docker-ce-17.03.1.ce-1.el7.centos.x86_64 --> Processing Dependency: libseccomp.so.2()(64bit) for package: docker-ce-17.03.1.ce-1.el7.centos.x86_64 --> Running transaction check ---> Package docker-ce-selinux.noarch 0:17.03.1.ce-1.el7.centos will be installed --> Processing Dependency: policycoreutils-python for package: docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch ---> Package libcgroup.x86_64 0:0.41-11.el7 will be installed ---> Package libseccomp.x86_64 0:2.3.1-2.el7 will be installed --> Running transaction check ---> Package policycoreutils-python.x86_64 0:2.5-11.el7_3 will be installed --> Processing Dependency: setools-libs >= 3.3.8-1 for package: policycoreutils-python-2.5-11.el7_3.x86_64 --> Processing Dependency: libsemanage-python >= 2.5-5 for package: policycoreutils-python-2.5-11.el7_3.x86_64 --> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-11.el7_3.x86_64 --> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-11.el7_3.x86_64 --> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64 --> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64 --> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64 --> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-11.el7_3.x86_64 --> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64 --> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-11.el7_3.x86_64 --> Running transaction check ---> Package audit-libs-python.x86_64 0:2.6.5-3.el7_3.1 will be installed ---> Package checkpolicy.x86_64 0:2.5-4.el7 will be installed ---> Package libsemanage-python.x86_64 0:2.5-5.1.el7_3 will be installed ---> Package python-IPy.noarch 0:0.75-6.el7 will be installed ---> Package setools-libs.x86_64 0:3.3.8-1.1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ===================================================================================================================== Package Arch Version Repository Size ===================================================================================================================== Installing: docker-ce x86_64 17.03.1.ce-1.el7.centos docker-ce-stable 19 M Installing for dependencies: audit-libs-python x86_64 2.6.5-3.el7_3.1 update 70 k checkpolicy x86_64 2.5-4.el7 base 290 k docker-ce-selinux noarch 17.03.1.ce-1.el7.centos docker-ce-stable 28 k libcgroup x86_64 0.41-11.el7 base 65 k libseccomp x86_64 2.3.1-2.el7 base 56 k libsemanage-python x86_64 2.5-5.1.el7_3 update 104 k policycoreutils-python x86_64 2.5-11.el7_3 update 445 k python-IPy noarch 0.75-6.el7 base 32 k setools-libs x86_64 3.3.8-1.1.el7 base 612 k Transaction Summary ===================================================================================================================== Install 1 Package (+9 Dependent packages) Total download size: 20 M Installed size: 24 M Is this ok [y/d/N]: y Downloading packages: (1/10): audit-libs-python-2.6.5-3.el7_3.1.x86_64.rpm | 70 kB 00:00:00 (2/10): checkpolicy-2.5-4.el7.x86_64.rpm | 290 kB 00:00:00 (3/10): libseccomp-2.3.1-2.el7.x86_64.rpm | 56 kB 00:00:00 (4/10): libcgroup-0.41-11.el7.x86_64.rpm | 65 kB 00:00:00 (5/10): policycoreutils-python-2.5-11.el7_3.x86_64.rpm | 445 kB 00:00:00 (6/10): setools-libs-3.3.8-1.1.el7.x86_64.rpm | 612 kB 00:00:00 (7/10): libsemanage-python-2.5-5.1.el7_3.x86_64.rpm | 104 kB 00:00:00 (8/10): python-IPy-0.75-6.el7.noarch.rpm | 32 kB 00:00:00 warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY Public key for docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm is not installed (9/10): docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch.rpm | 28 kB 00:00:00 (10/10): docker-ce-17.03.1.ce-1.el7.centos.x86_64.rpm | 19 MB 00:00:00 --------------------------------------------------------------------------------------------------------------------- Total 23 MB/s | 20 MB 00:00:00 Retrieving key from https://download.docker.com/linux/centos/gpg Importing GPG key 0x621E9F35: Userid : "Docker Release (CE rpm) <docker@docker.com>" Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35 From : https://download.docker.com/linux/centos/gpg Is this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libcgroup-0.41-11.el7.x86_64 1/10 Installing : setools-libs-3.3.8-1.1.el7.x86_64 2/10 Installing : checkpolicy-2.5-4.el7.x86_64 3/10 Installing : libsemanage-python-2.5-5.1.el7_3.x86_64 4/10 Installing : audit-libs-python-2.6.5-3.el7_3.1.x86_64 5/10 Installing : python-IPy-0.75-6.el7.noarch 6/10 Installing : policycoreutils-python-2.5-11.el7_3.x86_64 7/10 Installing : docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch 8/10 setsebool: SELinux is disabled. libsemanage.semanage_direct_install_info: Overriding docker module at lower priority 100 with module at priority 400. Installing : libseccomp-2.3.1-2.el7.x86_64 9/10 Installing : docker-ce-17.03.1.ce-1.el7.centos.x86_64 10/10 Verifying : libseccomp-2.3.1-2.el7.x86_64 1/10 Verifying : python-IPy-0.75-6.el7.noarch 2/10 Verifying : audit-libs-python-2.6.5-3.el7_3.1.x86_64 3/10 Verifying : libsemanage-python-2.5-5.1.el7_3.x86_64 4/10 Verifying : docker-ce-selinux-17.03.1.ce-1.el7.centos.noarch 5/10 Verifying : libcgroup-0.41-11.el7.x86_64 6/10 Verifying : policycoreutils-python-2.5-11.el7_3.x86_64 7/10 Verifying : docker-ce-17.03.1.ce-1.el7.centos.x86_64 8/10 Verifying : checkpolicy-2.5-4.el7.x86_64 9/10 Verifying : setools-libs-3.3.8-1.1.el7.x86_64 10/10 Installed: docker-ce.x86_64 0:17.03.1.ce-1.el7.centos Dependency Installed: audit-libs-python.x86_64 0:2.6.5-3.el7_3.1 checkpolicy.x86_64 0:2.5-4.el7 docker-ce-selinux.noarch 0:17.03.1.ce-1.el7.centos libcgroup.x86_64 0:0.41-11.el7 libseccomp.x86_64 0:2.3.1-2.el7 libsemanage-python.x86_64 0:2.5-5.1.el7_3 policycoreutils-python.x86_64 0:2.5-11.el7_3 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-1.1.el7 Complete!

    九、启动docker并加入开机启动

    $ sudo systemctl start docker
    $ sudo systemctl enable docker

    或者(推荐上面的)
    $ sudo service docker start
    service docker start #启动docker
    chkconfig docker on #加入开机启动

    十、验证安装是否成功(有client和service两部分表示docker安装启动都成功了)

    docker version

    
    

    十一、测试容器

        sudo docker run hello-world   #基于hello-world镜像启动一个容器,如果本地没有镜像会从公网拉取过来,这次做为测试用

      sudo docker info #查看信息

    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    78445dd45222: Pull complete
    Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    
    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
     3. The Docker daemon created a new container from that image which runs the
        executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it
        to your terminal.
    
    To try something more ambitious, you can run an Ubuntu container with:
     $ docker run -it ubuntu bash
    
    Share images, automate workflows, and more with a free Docker ID:
     https://cloud.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/engine/userguide/

      

    二、问题

    1、因为之前已经安装过旧版本的docker,在安装的时候报错如下:

    复制代码
    Transaction check error:
      file /usr/bin/docker from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
      file /usr/bin/docker-containerd from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
      file /usr/bin/docker-containerd-shim from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
      file /usr/bin/dockerd from install of docker-ce-17.12.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64
    复制代码

    2、卸载旧版本的包

    $ sudo yum erase docker-common-2:1.12.6-68.gitec8512b.el7.centos.x86_64

    3、再次安装docker

    $ sudo yum install docker-ce
  • 相关阅读:
    滑动窗口法与剑指offer:和为S的连续正数数列 与 和为S的两个数字
    数组中的逆序对与归并中的分治思想
    重读STL源码剖析:迭代器
    重读深度探索C++对象模型:函数
    FreeMarker笔记 前言&第1章 入门
    分享我的PL/SQL的优化设置,为开发全面提速
    迅影QQ视频查看v2.0 源码
    Invalid encoding name "UTF8". 报错 XML
    [HNOI2003]消防局的设立
    We need water!
  • 原文地址:https://www.cnblogs.com/liuzhiyun/p/11425512.html
Copyright © 2011-2022 走看看