# 看当前的内核版本,要求不低于**3.10**。 uname -r cat /proc/version # 堆代码 duidaima.com # 使用 yum 工具更新系统到最新。 yum update # 卸载旧的 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 # 安装需要的软件包, yum-util 提供 yum-config-manager 功能,另外两个是 devicemapper 驱动依赖 yum install -y yum-utils device-mapper-persistent-data lvm2 # 设置 yum 源 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo执行完后,会在 /etc/yum.repos.d创建一个Docker源的配置文件。
# 查看所有仓库中所有 docker 版本,并选择特定版本安装 yum list docker-ce --showduplicates | sort -r # 安装Docker,默认是安装最新的版本 yum install docker-ce yum install docker-ce-<VERSION STRING> # 例如:sudo yum install docker-ce-18.03.0.ce # 启动 Docker 服务,并加入开机启动 systemctl start docker systemctl enable docker区镜像源
阿里云容器服务:https://cr.console.aliyun.com/,首页点击【创建我的容器镜像】 得到一个专属的镜像加速地址,类似于 https://1234abcd.mirror.aliyuncs.com
打开 /etc/docker/daemon.json文件(没有时新建该文件),添加如下内容。也添设置其它加速站,如阿里、DaoCloud。
{"registry-mirrors":["https://registry.docker-cn.com"]}3.重启 Docker 服务,使配置生效
systemctl restart docker4.查看当前注册的镜像源列表,验证配置是否生效
docker info # 显示如下信息 Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: https://registry.docker-cn.com/ http://hub-mirror.c.163.com/ https://docker.mirrors.ustc.edu.cn/ Live Restore Enabled: false
# 删除旧版本 apt-get remove docker docker-engine docker.io # 更新系统 apt-get update # 支持https apt-get install apt-transport-https ca-certificates curl software-properties-common # 添加官方GPG KEY curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # 确认密钥:9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 apt-key fingerprint 0EBFCD88 # 添加稳定的 docker 仓库 add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# 安装 docker-ce apt-get install docker-ce # 获取 docker 版本列表 apt-cache madison docker-ce # 安装指定版本,例如:docker-ce=18.03.0~ce-0~ubuntu apt-get install docker-ce=<VERSION>
docker version2.运行最简的项目:hello-world
docker run hello-world # 如果没有该镜像,则会自动下载。运行内容显示:This message shows that your installation appears to be working correctly. 表示安装成功。3.卸载
yum remove docker-ce rm -rf /var/lib/dockerUbuntu-卸载 docker-ce
apt-get purge docker-ce rm -rf /var/lib/docker