一、背景
由于公司内部网络原因,无法使用在线安装Docker;试了很多种离线安装方式,由于Docker依赖了很多rpm,要离线安装必须得先安装依赖(较为麻烦,遂放弃);最后使用二进制方式安装:把Docker注册为服务
二、准备
参考文档:https://docs.docker.com/install/linux/docker-ce/binaries/#install-static-binaries
下载地址:https://download.docker.com/linux/static/stable/x86_64/
三、安装
1、解压
$ tar xzvf /path/to/<FILE>.tar.gz
2、将二进制文件移动到可执行文件路径上的目录中,例如/usr/bin/。如果跳过此步骤,则必须在调用docker或dockerd命令时提供可执行文件的路径。
$ cp docker/* /usr/bin/
3、启动Docker守护程序(此方式只是临时启动,重启后还需要重新启动,可跳过此步骤)
$ dockerd &
如果需要使用其他选项启动守护程序,请相应地修改上述命令,或者创建并编辑该文件/etc/docker/daemon.json 以添加自定义配置选项
3、将docker注册为service
$ vim /etc/systemd/system/docker.service
将以下内容拷贝到docker.service中
[Unit]
Description=Docker Application Container Engine
Documentation=[https://docs.docker.com](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
4、启动
# 赋予权限
$ chmod +x /etc/systemd/system/docker.service
# 重新加载
$ systemctl daemon-reload
#启动Docker
$ systemctl start docker
#设置开机自启
$ systemctl enable docker.service
5、检查是否安装成功
#查看Docker状态
$ systemctl status docker
#查看Docker版本
$ docker -v