跳到主要内容

Linux离线安装Docker

· 阅读需 3 分钟

如何在Linux离线下进行Docker安装。

本地环境

安装步骤

首先把下载好的Docker压缩包放到Linux根目录中

执行解压命令将压缩包进行解压到指定目录

tar zxvf docker-19.03.1.tar
sudo cp docker/* /usr/bin/
  • 小提示

    安装好后不要忘记把根目录的压缩包删除,回到根目录执行命令 rm -f docker-19.03.1.tar 要是可以直接ssh的,可以直接在本地把压缩包解压,然后把docker目录直接拽过去就好。

执行启动命令

sudo dockerd

然后查看一下docker版本号是否有了。 docker -v

将docker注册为service

  • 新建docker.service文件
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
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
  • 执行命令

    添加文件权限并启动docker

      chmod +x /etc/systemd/system/docker.service

    重载unit配置文件

      systemctl daemon-reload

    启动Docker

      systemctl start docker

    设置开机自启

      systemctl enable docker.service
  • 常用命令

    重启docker

      systemctl restart docker

    关闭docker

      systemctl stop docker