Docker安装
前言
本文介绍了Docker在linux环境下的安装,还有相关镜像的配置。
安装前提条件
目前,CentOS 仅发行版本中的内核支持 Docker。Docker 运行在CentOS 7 (64-bit)上,
要求系统为64位、Linux系统内核版本为 3.8以上,这里选用Centos7.9
查看自己的内核
uname命令用于打印当前系统相关信息(内核版本号、硬件架构、主机名称和操作系统类型等)。
# uname -r
3.10.0-1160.el7.x86_64
# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
安装步骤
yum安装gcc相关
yum -y install gcc
yum -y install gcc-c++
安装需要的软件包
yum install -y yum-utils
设置stable镜像仓库
yum-config-manager --add-repo
https://download.docker.com/linux/centos/docker-ce.repo
#默认是从国外的,不推荐
#推荐使用国内的
yum-config-manager --add-repo
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新yum软件包索引
yum makecache fast
安装DOCKER CE
yum -y install docker-ce docker-ce-cli containerd.io
启动Docker
# systemctl start docker
查看docker信息
# docker version
成功启动会显示版本信息
测试
# 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:
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.
阿里云镜像加速
登录阿里云网站,选择容器镜像服务
点击管理控制台
在镜像加速器中可以看到自己的加速器地址
按照网站提供的操作文档操作即可
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://{自已的编码}.mirror.aliyuncs.com"]
}
EOF
# 重启docker
systemctl daemon-reload
systemctl restart docker