Centos安装Docker

本文详细介绍了在Centos系统上安装Docker CE的过程,包括系统准备、外网和内网安装步骤、验证方法及常见配置调整,适用于初学者和有经验的系统管理员。

一、简介

二、准备

Docker 要求 CentOS 系统的内核版本高于 3.10

uname -r

使用 root 登录 Centos。确保 yum 包更新到最新。

sudo yum update

卸载旧版本

sudo yum remove docker docker-common docker-selinux docker-engine

安装依赖

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

三、安装

外网安装
  • 设置yum源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  • 查看所有仓库中所有docker版本
yum list docker-ce --showduplicates | sort -r
  • 安装
sudo yum install docker-19.03.4
  • 设置开机自启
$ sudo systemctl enable docker
  • 启动docker
$ sudo systemctl start docker
内网安装
  • 解压
tar -zxvf docker-19.03.4.tgz
  • 将解压出来的docker文件内容移动到/usr/bin/目录下
cp docker/* /usr/bin/
  • 将docker注册为service
vim /etc/systemd/system/docker.service

内容

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target
  • 添加文件权限
chmod +x /etc/systemd/system/docker.service

1.docker默认网关IP为172.17网段,如果本地网络为172.17,则需要修改docker默认网关IP,防止与本地网络产生冲突。
2./etc/docker/daemon.json 是 docker 的配置文件,默认是没有的,需要手动创建。

cat << EOF > /etc/docker/daemon.json
{
  "bip": "172.27.0.1/16"
}
EOF
  • 重载unit配置文件
systemctl daemon-reload
  • 设置开机自启
systemctl enable docker.service
  • 启动docker
systemctl start docker

四、验证

  • 查看Docker状态
systemctl status docker
  • 查看Docker版本
docker -v
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码上富贵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值