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-eng

3. 安装Docker CE

3.1 通过资源库安装

3.1.1 安装所需要的包。

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

	yum install -y yum-utils
3.1.2 添加安装所需要的官方源。
#设置镜像
    yum-config-manager \
        --add-repo \
        https://download.docker.com/linux/centos/docker-ce.repo
#这里我们使用阿里云的
    yum-config-manager \
        --add-repo \
        http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#这里我们使用腾讯云的
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
sudo sed -i 's+download.docker.com+mirrors.cloud.tencent.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
#更新软件包索引
	yum makecache fast
3.1.3 安装Docker CE
a 安装Docker CE的最新版本
#docker-ce 社区版 ee 企业版
    yum install -y docker-ce docker-ce-cli containerd.io
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/

#查看下载的hello-world镜像
[root@VM-16-11-centos ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    d1165f221234   7 weeks ago   13.3kB

4. 了解卸载Docker CE

    #卸载依赖
    yum remove docker-ce docker-ce-cli containerd.io
    #删除主机上所有镜像、容器和卷
    rm -rf /var/lib/docker
    rm -rf /var/lib/containerd

配置镜像加速


cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": [
"https://mirror.ccs.tencentyun.com"
  ]
}
EOF

systemctl daemon-reload
systemctl restart docker
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值