CentOS7.9 离线安装 Docker

首先下载 Docker 的离线二进制安装包

https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz

如需安装其他版本请自行更换链接地址,后续步骤一样

## 解压文件
tar -zxvf docker-20.10.9.tgz

## 将docker下的所有文件复制到指定目录
sudo cp docker/* /usr/bin/

新建配置文件: /etc/docker/daemon.json,粘贴以下文件,部分解释如下

  • 配置镜像源,加速下载镜像
  • 根据电脑实际情况指定docker数据的根目录
  • data-root目录应该选择一个较大的磁盘位置
{
  "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn",
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn"
  ],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "200m",
    "max-file": "3"
  },
  "data-root": "/docker/dockerData"
}

Docker使用systemctl管理,非常关键的步骤

vim /usr/lib/systemd/system/docker.service

复制到文件中即可

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service

[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
TimeoutStartSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# 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

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# 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
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

使配置文件生效 sudo systemctl daemon-reload
启动 docker服务 sudo systemctl start docker.service
配置 docker 开机自启动 sudo systemctl enable docker.service
查看 docker 运行状态 sudo systemctl enable docker.service

安装docker-compose教程

# 下载安装包,链接中的版本可自行替换
sudo curl -L "https://github.com/docker/compose/releases/download/2.20.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 给文件添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
# 查看版本号,正确输出代表安装成功
docker-compose --version
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值