赞
踩
Docker从17.03版本之后分为CE(Community Edition: 社区版)和EE(Enterprise Edition: 企业版)。相对于社区版本,企业版本强调安全性,但需付费使用。这里我们使用社区版本即可。
Docker支持64位版本的CentOS 7和CentOS 8及更高版本,它要求Linux内核版本不低于3.10。
查看Linux版本的命令这里推荐两种:lsb_release -a或cat /etc/redhat-release。
lsb_release -a查看效果:
[ ~]$ lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.6.1810 (Core)
Release: 7.6.1810
Codename: Core
cat /etc/redhat-release查看版本效果:
[~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
显然,当前Linux系统为CentOS7。再查一下内核版本是否不低于3.10。
查看内核版本有三种方式:
cat /proc/version
uname -a
uname -r
三种形式都可以查看到内容版本,比如:
[ ~]$ uname -r
3.10.0-1160.45.1.el7.x86_64
可以看到,当前Linux内核版本满足Docker的需要。
注意:更换镜像源站为阿里云
以 CentOS 7 (使用yum进行安装) 为例进行讲解:
Docker官方和国内daocloud都提供了一键安装的脚本,使得Docker的安装更加便捷。
官方的一键安装方式:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
国内 daocloud一键安装命令:
curl -sSL https://get.daocloud.io/docker | sh
执行上述任一条命令,耐心等待即可完成Docker的安装。
建议初学者以手动安装为主,进行学习。
手动安装Docker分三步:卸载、设置仓库、安装。
第一步,卸载历史版本。这一步是可选的,如果之前安装过旧版本的Docker,可以使用如下命令进行卸载:
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine \
docker-ce
在设置仓库之前,需先安裝所需的软件包。yum-utils提供了yum-config-manager,并且device mapper存储驱动程序需要device-mapper-persistent-data和lvm2。
$ yum install -y yum-utils device-mapper-persistent-data lvm2
执行结果:
$ sudo 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
执行结果:
仓库设置完毕,即可进行Docker的安装。
执行一下命令,安装最新版本的 Docker Engine-Community 和 containerd。
yum makecache fast
执行结果:
yum install docker-ce
docker-ce为社区免费版本。稍等片刻,docker即可安装成功。但安装完成之后的默认是未启动的,需要进行启动操作。
如需要docker-ce-cli或containerd.io或docker-buildx-plugin 或 docker-compose-plugin可执行如下命令:
yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
执行结果
至此,完成Docker安装。
systemctl start docker
或
service docker start
// 拉取镜像(可跳过)
docker pull hello-world
// 执行hello-world
docker run hello-world
如果执行之后,控制台显示如下信息,则说明Docker安装和启动成功:
docker ps -a
docker version
除了启动Docker,一些其他启动相关的命令:
docker version
systemctl daemon-reload
systemctl restart docker / service docker restart
docker service docker stop / docker systemctl stop docker
删除安装包:
yum remove docker-ce
删除镜像、容器、配置文件等内容:
rm -rf /var/lib/docker
安装完成Docker之后,这里汇总列一下常见的Docker操作命令:
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。