本实例使用yum进行安装
如果安装过Docker需使用如下命令卸载
yum remove docker docker-common docker-selinux docker-engine
安装仓库
1.执行以下命令,安装docker所需的包。其中yum-utils提供了yum-config-manager工具;
device-mapper-persistent-data 及 lvm2则是devicemapper存储驱动所需要的包
yum install -y yum-utils device-mapper-persistent-data lvm2
2.执行如下命令,安装stable仓库。必须安装stable仓库,即使你想安装edge或test仓库中的docker构建版本。
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安装Docker CE
1.执行以下命令,更新yum的包索引
yum makecache fast
2.执行以下命令即可安装最新版本的Docker CE
yum install docker-ce
3.在生成环境中,可能需要指定想要的安装版本,此时可使用如下命令列出可用的docker版本
yum list docker-ce.x86_64 --showduplicates | sort -r
列出版本后,可使用如下命令安装想要安装的Docker CE版本
yum install docker-ce-<VERSION>
4.启动Docker
systemctl start docker
5.验证Docker是否安装成功
docker run hello-world
出现如下输出 说明安装成功
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:4df8ca8a7e309c256d60d7971ea14c27672fc0d10c5f303856d7bc48f8cc17ff
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/
升级Docker CE
yum makecache fast
然后按照安装Docker的步骤,即可完成安装升级
卸载Docker
1.删除Docker软件包
yum remove docker-ce
2.如要删除Docker存储的文件,例如镜像,容器,卷等信息,需执行以下信息
rm -rf /var/lib/docker