Dockr CE在Centos 7上的安装部署

官方文档:https://docs.docker.com/install/linux/docker-ce/centos/

1. 系统环境

    [root@linux-node2 ~]# cat /etc/redhat-release 
    CentOS Linux release 7.1.1503 (Core) 
    [root@linux-node2 ~]# uname -r
    3.10.0-229.el7.x86_64
    [root@linux-node2 ~]# getenforce 
    Disabled
    [root@linux-node2 ~]# systemctl status firewalld
    firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled)
       Active: inactive (dead)

2. 旧版本移除

    [root@linux-node2 ~]# yum remove docker \
    >                   docker-client \
    >                   docker-client-latest \
    >                   docker-common \
    >                   docker-latest \
    >                   docker-latest-logrotate \
    >                   docker-logrotate \
    >                   docker-selinux \
    >                   docker-engine-selinux \
    >                   docker-engine
    Loaded plugins: fastestmirror, langpacks
    No Match for argument: docker
    No Match for argument: docker-client
    No Match for argument: docker-client-latest
    No Match for argument: docker-common
    No Match for argument: docker-latest
    No Match for argument: docker-latest-logrotate
    No Match for argument: docker-logrotate
    No Match for argument: docker-selinux
    No Match for argument: docker-engine-selinux
    No Match for argument: docker-engine
    No Packages marked for removal

3. 安装Docker CE

3.1 通过资源库安装

3.1.1 安装所需要的包。

yum-utils提供了yum-config-manager实用程序,devicemapper存储驱动程序需要设备-mapper-persistent-data和lvm2。

    yum install -y yum-utils \
      device-mapper-persistent-data \
      lvm2
3.1.2 添加安装所需要的官方源。
    yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo
3.1.3 安装Docker CE
a 安装Docker CE的最新版本
    yum install docker-ce

如果提示接受GPG密钥,验证指纹匹配060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35,如果是,接受。

b 安装Docker CE的指定版本
    yum list docker-ce --showduplicates | sort -r
    docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable
    docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable
    docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.03.3.ce-1.el7                    docker-ce-stable
    docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
    docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
    #返回的列表取决于启用了哪些存储库,并且特定于您的CentOS版本
    yum install docker-ce-18.06.1.ce
    #yum install docker-ce-
3.1.4 启动docker
    #启动docker
    systemctl start docker
    
    #通过运行hello-world镜像来验证docker是否正确安装。
    #这个命令下载一个测试映像并在容器中运行它。当容器运行时,它打印一条信息消息并退出。
    docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    d1725b59e92d: Pull complete 
    Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
    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.
        (amd64)
     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://hub.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/get-started/

3.2 通过RPM包安装

3.2.1 下载Docker CE的RPM包

访问https://download.docker.com/linux/centos/7/x86_64/stable/Packages/,下载您想要安装的Docker版本的.rpm文件。

3.2.2 安装Docker CE

yum install /path/to/package.rpm

3.2.3 启动docker
    #启动docker
    systemctl start docker
    
    #通过运行hello-world镜像来验证docker是否正确安装。
    #这个命令下载一个测试映像并在容器中运行它。当容器运行时,它打印一条信息消息并退出。
    docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    d1725b59e92d: Pull complete 
    Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
    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.
        (amd64)
     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://hub.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/get-started/

4. 卸载Docker CE

    #卸载docker包
    yum remove docker-ce
    #删除主机上所有图像、容器和卷
    rm -rf /var/lib/docker

你可能感兴趣的:(Linux运维)