1. 程式人生 > >Dockr CE在Centos 7上的安裝部署

Dockr CE在Centos 7上的安裝部署

1. 系統環境

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

2. 舊版本移除

    [[email protected] ~]# 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-<VERSION STRING>
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