1.离线安装

官方文档,https://docs.docker.com/engine/install/binaries/#install-daemon-and-client-binaries-on-linux

1.下载

https://download.docker.com/linux/static/stable/x86_64/

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

2.安装

#解压
 tar zxvf docker-20.10.9.tgz
 #复制
 cp -p docker/* /usr/bin

3.注册服务

#注册为系统服务
/usr/lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target docker.socket
[Service]
Type=notify
EnvironmentFile=-/run/flannel/docker
WorkingDirectory=/usr/local/bin
ExecStart=/usr/bin/dockerd \
                -H tcp://0.0.0.0:4243 \
                -H unix:///var/run/docker.sock 
#                --selinux-enabled=false \
#                --log-opt max-size=1g
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=on-failure
[Install]
WantedBy=multi-user.target

4.配置daemon

cat > /etc/docker/daemon.json << EOF
{
    "exec-opts": ["native.cgroupdriver=systemd"],
    "max-concurrent-downloads": 10,
    "max-concurrent-uploads": 5,
    "log-driver": "json-file",
    "storage-driver": "overlay2",
    "data-root": "/data/docker",
    "storage-opts": [
    	"overlay2.override_kernel_check=true"
    ],
    "log-opts":{
        "max-size": "300m",
        "max-file": "2" 
    },
    "live-restore": true
}
EOF

5.普通用户操作docker

#新建用户组
groupadd docker

#把用户添加到docker组中
usermod -aG docker ec2-user

#更新组
newgrp docker