1. 下载
到以下地址 下载最新版本的docker-..*.tgz,此时最新的版本是docker-26.1.3.tgz
https://download.docker.com/linux/static/stable/x86_64/
2. 安装
2.1. 上传文件到任意目录(如/root)
2.2. 将下载得文件上传到Linux系统后使用下面命令进行解压
tar -zxvf docker-26.1.3.tgz
2.3. 解压后使用下面命令将整个docker文件夹复制到/usr/bin/目录
cp docker/* /usr/bin/
2.4. 执行命令
[root@localhost ~]# docker -v
Docker version 26.1.3, build b72abbb
3. 设置开机自启动
整个docker已经安装完了,但是,这样当服务器重启后会需要手动启动docker服务,咱们要改成服务开机自启动。
3.1. 设置docker启动服务,新建启动服务文件
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 -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
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
systemctl daemon-reload # 重载systemd下 xxx.service文件
systemctl start docker # 启动Docker
systemctl enable docker.service # 设置开机自启
测试是否成功:
systemctl status docker # 查看Docker状态
docker -v # 查看Docker版本
执行完 docker ps命令后显示以下第3条内容就代表整个docker服务已经完全启动成功了,接下来就可以开始docker部署服务之旅
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
参考资料:RedHat7离线安装docker