CentOs7 安装 Docker

卸载旧版本

$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

设置yum仓库

# 安装所需的包
sudo yum install -y yum-utils

# 设置使用稳定存储库
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

安装

安装最新版
sudo yum install docker-ce docker-ce-cli containerd.io

# 安装模块介绍
containerd.io - daemon to interface with the OS API (in this case, LXC - Linux Containers), essentially decouples Docker from the OS, also provides container services for non-Docker container managers

docker-ce - Docker daemon, this is the part that does all the management work, requires the other two on Linux

docker-ce-cli - CLI tools to control the daemon, you can install them on their own if you want to control a remote Docker daemon

安装指定版本
# 列出可用版本
yum list docker-ce --showduplicates | sort -r

docker-ce.x86_64            3:19.03.9-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.3-3.el7                     docker-ce-stable

# 安装命令
sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

# eg
sudo yum install docker-ce-19.03.9 docker-ce-cli-19.03.9 containerd.io
安装过程报错
# 缺少 container-selinux 依赖
Error: Package: containerd.io-1.2.13-3.2.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74
Error: Package: 3:docker-ce-19.03.12-3.el7.x86_64 (docker-ce-stable)
           Requires: container-selinux >= 2:2.74
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

# 解决
1. 官网查看 container selinux pacakge:
http://mirror.centos.org/centos/7/extras/x86_64/Packages/

2. 安装 container-selinux
sudo yum -y install http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.107-3.el7.noarch.rpm

Docker 启动

# 启动 Docker
sudo systemctl start docker

# 查看Docker启动状态
systemctl status docker

CentOs7 安装 Docker_第1张图片

配置 Docker 镜像加速

vim vim /etc/docker/daemon.json

# 输入如下内容
{
 "registry-mirrors": ["http://hub-mirror.c.163.com"]
}

重新加载配置文件,重启 docker 服务

systemctl daemon-reload
systemctl restart docker.service

常用命令

# 查看版本
docker version

# 查看Docker的系统信息
docker info

# 查看镜像
docker images

# 拉取镜像
docker pull

# 推送镜像
docker push

# 查看运行中的容器
docker ps

你可能感兴趣的:(Devops,Linux)