Docker安装(Linux CentOS)

Avatar photo

前置任务:

  1. 查看Linux内核版本,必须在3.10以上才能安装,通过uname -r查看。
  2. 更新yum:
    sudo yum update
  3. 删除老的docker:
    sudo yum remove docker \docker-client \docker-client-laster \docker-common \docker-latest \docker-latest-logrotate \docker-engine

安装:

  1. 建立Docker仓库sudo yum install -y yum-utils
  2. 添加镜像仓库
    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
  3. 安装docker引擎sudo yum install docker-ce docker-ce-cli contanerd.io
  4. 启动docker:sudo systemctl start docker
  5. 测试安装是否成功sudo docker run hello-world
  6. 关闭firewall:
    systemctl disable firewalld
    systemctl stop firewalld
  7. 安装iptables-services:
    yum install iptables-services
    systemctl start iptables

ps: 应该先装iptables 再装docker,否则需要重启docker写入路由表,然后用iptables-save > /etc/sysconfig/iptables 保存成永久的。