Docker 是一个开源 的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux 或 Windows 机器上,也可以实现 虚拟化 。容器是完全使用 沙箱 机制,相互之间不会有任何接口。-- 来自百度百科
官方网址:Empowering App Development for Developers | Docker
安装至 Centos 官方文档:Install Docker Engine on CentOS | Docker Documentation
以下内容全部来自官方文档的翻译与总结
前提条件
Docker 要安装在 CentOS 7 上,需要系统为 64 位,内核版本为 3.10 以上
# 查看当前系统的内核版本,必须高于 3.10
$ uname -r
3.10.0-862.9.1.el7.x86_64
# 查看 centos 版本
$ cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
卸载旧版本
$ yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
安装 yum-utils 包(它提供 yum-config-manager 实用程序)并设置稳定存储库
$ sudo yum install -y yum-utils
# 这条命令使用了 docker 的官方镜像,因为服务器架设国外的原因,下载可能会很慢,所以建议使用下面的 阿里云镜像
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# 阿里云镜像
$ sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装 Docker 引擎
$ yum install docker-ce docker-ce-cli containerd.io
也可以选择安装指定版本:
# 列出版本
$ yum list docker-ce --showduplicates | sort -r
docker-ce.x86_64 3:20.10.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.9-3.el7 @docker-ce-stable
docker-ce.x86_64 3:20.10.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:20.10.5-3.el7 docker-ce-stable
# 安装指定版本
$ yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
开启 Docker
$ systemctl start docker
运行 hello-world 镜像
$ docker run hello-world
查看当前服务器下的所有镜像
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB