Linux 下安装 docker 服务(在线安装与离线安装)

Linux 下安装 docker 服务

一、在线安装

1、更新 yum 源

yum update
#选择版本安装 不加版本号 默认最新版本

2、安装 docker

# 不指定版本安装,默认安装最新版
yum install -y docker-ce
# 指定版本安装
yum -y install docker-ce-20.10.6-3.el7

二、离线安装

1、下载 docker 安装包

docker所有版本:​ ​
https://download.docker.com/linux/static/stable/
尽量不下载最新版本

2、解压安装包

tar -xvf docker-20.10.x.tgz

3、移动解压后的安装包

# 拷贝文件到 /usr/bin 目录下
cp docker/* /usr/bin/

4、将docker注册为service系统服务

# 创建配置文件
vi /etc/systemd/system/docker.service
# 将下列配置加到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

5、更改文件权限,并重载 unit 配置文件

#docker启动脚本赋予权限
chmod +x /etc/systemd/system/docker.service

#重载unit配置文件
systemctl daemon-reload

6、运行docker命令

# 启动Docker
systemctl start docker

# 重启 docker
systemctl restart docker

# 停止 docker
systemctl  stop docker

# 查看Docker状态
systemctl status docker

# 配置开机docker自启 (
# 该步骤可配可不配,根据自己实际需要进行选择配置
# 不配置---------当服务器宕机重启后,docker 服务不会随系统启动
# 配置 -----------当服务器宕机重启后,docker 服务会随系统启动
systemctl enable docker.service

7、查看docker版本

# 查看版本
docker -v

# 查看 docker 详情
docker info
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值