{card-describe title="前言"}
Docker是一个镜像文件的分发与运行平台,我们可以在任何安装了Docker的平台上以你的方式构建、管理和保护你的应用。
{/card-describe}
{mtitle title="正文开始"/}
{lamp/}
安装要求
- 本教程只教授CentOS Linux系统下Docker的安装
- Docker分为Docker CE与Docker EE,前者为社区免费版,后者为商业收费版。本教程安装的是Docker CE
Docker支持以下版本的CentOS:
- CentOS 7 (64-bit)
- CentOS 6.5 (64-bit) 或更高的版本
目前,CentOS 仅发行版本中的内核支持 Docker
- Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上
- Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本
{dotted startColor="#ff6c6c" endColor="#1989fa"/}
使用yum安装
确认系统版本
Docker 要求 CentOS 系统的内核版本高于 3.10 ,在终端中通过 uname -r 命令查看你当前的内核版本
移除旧版本
如果不确定当前系统是否安装了Docker则可以使用以下命令来执行检查并清理旧版本
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine安装必要工具
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2添加Docker软件源信息
$ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo更新yum缓存
$ sudo yum makecache fast安装Docker CE
$ sudo yum -y install docker-ce启动Docker后台服务
$ sudo systemctl start docker测试运行
- 可以使用
docker --version查看docker的版本
运行
docker run hello-world来运行测试镜像,出现如下内容则安装成功Hello from Docker!
This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps:
- The Docker client contacted the Docker daemon.
- The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64) - The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading. - 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 bashShare 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/
{dotted startColor="#ff6c6c" endColor="#1989fa"/}
使用脚本安装Docker
使用 sudo 或 root 权限登录 Centos
$ sudo -s
password:更新yum,确保其为最新版本
$ sudo yum update下载docker安装脚本并执行安装
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh{message type="info" content="执行这个脚本会添加 docker.repo 源并安装 Docker"/}
启动Docker进程
$ sudo systemctl start docker测试安装
$ sudo docker run hello-world{dotted startColor="#ff6c6c" endColor="#1989fa"/}
镜像加速
鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,我们需要配置加速器来解决,我使用的是中科大的镜像源,具体配置方法请查看官方说明:http://mirrors.ustc.edu.cn/help/dockerhub.html
{message type="success" content="ustc docker mirror的优势之一是,不需要注册,公共服务(这才是我熟悉的ustc嘛)。"/}
{lamp/}
{mtitle title="正文结束"/}
此处评论已关闭