首先下载 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