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

在这里插入图片描述

配置 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值