Loading... # 离线安装 Docker 指南 适用于内网或者离线安装 Docker # Docker 离线安装 ## 官方指南 官网教程: [从二进制文件安装 Docker 引擎 |Docker 文档](https://docs.docker.com/engine/install/binaries/#install-daemon-and-client-binaries-on-linux)  ## 下载二进制文件 首先去官网下载二进制文件 [Index of linux/static/stable/x86_64/ (docker.com)](https://download.docker.com/linux/static/stable/x86_64/)  如果是 arm 架构就访问 [Index of linux/static/stable/aarch64/ (docker.com)](https://download.docker.com/linux/static/stable/aarch64/) ## 上传安装包 ```bash pwd # 自定义文件目录用来存放docker的源码包 cd /usr/local # 解压二进制文件 tar -zxvf docker-24.0.7.tgz # 复制解压后文件到可执行路径 /usr/bin/ (必做), 成功复制后可删除 /usr/local/docker sudo cp docker/* /usr/bin/ ```  ## 配置 Docker 服务 配置 docker 为 service 服务 ```bash vi /etc/systemd/system/docker.service ``` 添加如下内容 ```bash [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewall.service Wants=network-online.target [Service] Type=notify #the default is not to use systemd for cgroups because the delegay 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 process 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 ### 添加可执行权限 ```bash chmod +x /etc/systemd/system/docker.service ``` ### 重新加载配置(启动后修改配置需执行) ```bash systemctl daemon-reload ``` ### 启动 Docker && 开机自启 ```bash systemctl start docker.service systemctl enable docker.service ``` ### 查看 Docker 状态 ```bash systemctl status docker.service ``` ### 查看 docker 版本信息 ```bash docker -v ``` --- # 离线添加镜像 可以使用内网的镜像仓库, 或者使用其他机器将公网镜像导出成 tar 压缩包后上传到内网机器中进行导入, 如果是自己的程序可直接使用 `Dockerfile` 进行镜像的构建 ## 镜像导出 ```bash -- docker save -o name.tar id/name docker save -o mysql.tar mysql:latest ``` ## 镜像导入 ```bash docker load -i mysql.tar ``` ## 查看镜像 ```bash docker images ``` ## 查看容器详细信息 ```bash docker inspect 容器ID ``` 最后修改:2024 年 07 月 18 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果文章有帮助到你,请随意赞赏
2 条评论
作者以简洁明了的语言,传达了深刻的思想和情感。
博主太厉害了!