Docker学习笔记02-安装

Docker的版本

Docker的版本分为Docker-ce社区版和Docker-ee企业版,想了解更多可以去官网查看
其中Docker-ce分为stable和edge版本

  • stable为季度发布版本,例如v17.03 v17.06发布周期为一个季度
  • edge为月度发布版本,例如v17.01 v17.02发布周期为一个月

安装前先在官网查看Docker支持的平台,不同系统下的安装方法也都可以在官网找到,这里以在CentOS7下安装为例

CentOS7下安装Docker-ce

OS requirements

To install Docker CE, you need a maintained version of CentOS 7. Archived versions aren’t supported or tested.

The centos-extras repository must be enabled. This repository is enabled by default, but if you have disabled it, you need to re-enable it.

The overlay2 storage driver is recommended.

查看系统需求提示需要一个处于维护版本的CentOS7即可

Uninstall old versions

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies.

如果之前安装过Docker,根据提示先清除老版本的Docker

[root@centos7 ~]# yum remove docker \
           docker-client \
           docker-client-latest \
           docker-common \
           docker-latest \
           docker-latest-logrotate \
           docker-logrotate \
           docker-selinux \
           docker-engine-selinux \
           docker-engine

仓库方式安装

推荐的方式,便于安装和升级

需要安装yum-config-manager来更方便的管理yum仓库,yum-config-manager在yum-utils包中,所以先安装yum-utils

[root@centos7 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

安装完后添加Docker-ce的官方源

[root@centos7 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

开启edge版本后,在选择指定版本安装时就能看到edge版本了

[root@centos7 ~]# yum-config-manager --enable docker-ce-edge

查看仓库列表检查是否添加成功

[root@centos7 ~]# yum repolist

安装最新版本

[root@centos7 ~]# yum install docker-ce

安装指定版本

先列出Docker仓库中可用的版本再选择安装,@代表已安装的软件包,返回的列表取决于启用了哪些仓库
其中EL是RedHatEnterpriseLinux的简写,其中el5/6/7的软件包用于Red Hat 5/6/7.x, CentOS 5/6/7.x, and CloudLinux 5/6/7.下的安装

[root@centos7 ~]# yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror
可安装的软件包
Loading mirror speeds from cached hostfile
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.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable

执行命令yum install docker-ce-<VERSION STRING>安装

[root@centos7 ~]# yum install docker-ce-18.03.1.ce-1.el7.centos

启动Docker服务

[root@centos7 ~]# systemctl start docker

验证Docker是否安装成功

[root@centos7 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9db2ca6ccae0: Pull complete 
Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
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/engine/userguide/

包方式安装

包方式安装需要下载.rpm文件进行安装,但当需要更新docker的时候也必须下载安装包来安装,下载地址

安装Docker的rpm包

[root@centos7 ~]# yum install docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm

启动Docker服务

[root@centos7 ~]# systemctl start docker

验证Docker是否安装成功

[root@centos7 ~]# docker run hello-world

卸载Docker

[root@centos7 ~]# yum remove docker-ce
[root@centos7 ~]# rm -rf /var/lib/docker
    原文作者:l0veyt
    原文地址: https://segmentfault.com/a/1190000015751390
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞