Docker安装教程
环境检查
1.查看系统的内核
uname -r
2.查看系统配置
cat /etc/os-release
官方文档地址
1.卸载旧版本的
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2.安装yum-utils包
sudo yum install -y yum-utils
3.设置镜像仓库
国外:
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
4.更新yum软件包索引
yum makecache fast
5.安装docker
最新版:
sudo yum install docker-ce docker-ce-cli containerd.io
查看列出并排序您的存储库中可用的版本指定版本:
yum list docker-ce --showduplicates | sort -r
安装指定版本:
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
6.启动docker
sudo systemctl start docker
7.查看是docker的状态:
systemctl status docker
注意:这里有一个很奇怪的问题当你停掉docker查看状态已经死亡但是当你用docker 命令去访问资源会自动启动。如果不想被访问时自动启动服务
sudo systemctl stop docker.socket
查看是docker的详细信息
docker version
8.重启docker
sudo systemctl restart docker
9.关闭docker
sudo systemctl stop docker
10.测试 hello world
sudo docker run hello-world
9.查看下载的镜像
docker images
11.卸载 Docker Engine、CLI 和 Containerd 包:
sudo yum remove docker-ce docker-ce-cli containerd.io
12.删除配置:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
13.配置阿里云镜像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://dppmapm2.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
14.配置docker开机自启
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
15.关闭docker开机自启
sudo systemctl disable docker.service
sudo systemctl disable containerd.service