资讯动态

Docker 入门篇(二)-- Linux 服务器离线安装 Docker环境

发布时间:2026/8/27 13:16:17 来源:尧图企业网站定制
引言docker 系列文章Docker 入门篇一-- 简介与安装教程Windows和Linux一、安装环境准备centos CentOS Linux release 7.6.1810 (Core)docker 版本docker-26.1.0.tgz官网下载地址点击下载docker-compose 版本v2.26.1官网下载地址点击下载二、安装方式一常规安装上传 安装包 到 服务器 /root 目录 进行解压tar-zxvfdocker-26.1.0.tgz复制文件将docker中的全部文件使用下边命令复制到/usr/bincp./docker/* /usr/bin创建docker.service文件# 进入 /etc/systemd/system/ 目录cd/etc/systemd/system/# 创建 docker.servicetouchdocker.service编辑docker.service文件# 编辑 docker.servicevimdocker.service将下边内容复制到docker.service。注意将其中的ip地址改成您的服务器地址其它参数不用改。–insecure-registry192.168.10.1[Unit]DescriptionDocker Application Container EngineDocumentationhttps://docs.docker.comAfternetwork-online.target firewalld.serviceWantsnetwork-online.target[Service]Typenotify# 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 dockerExecStart/usr/bin/dockerd --selinux-enabledfalse --insecure-registry192.168.10.1ExecReload/bin/kill-sHUP$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.LimitNOFILEinfinityLimitNPROCinfinityLimitCOREinfinity# Uncomment TasksMax if your systemd version supports it.# Only systemd 226 and above support this version.#TasksMaxinfinityTimeoutStartSec0# set delegate yes so that systemd does not reset the cgroups of docker containersDelegateyes# kill only the docker process, not all processes in the cgroupKillModeprocess# restart the docker process if it exits prematurelyRestarton-failureStartLimitBurst3StartLimitInterval60s[Install]WantedBymulti-user.target添加可执行权限chmodx /etc/systemd/system/docker.service重载配置文件systemctl daemon-reload启动dockersystemctl startdocker查看 docker 服务状态systemctl statusdocker设置开机自启动systemctlenabledocker.service三、安装方式二 docker 脚本安装创建 docker.service 文件在 docker-26.1.0.tgz同目录下 创建上文内容的 docker.service 文件新建安装脚本文件 docker-install.shtouchdocker-install.sh编辑docker-install.sh内容如下#!/bin/shecho解压tar包tar-xvf$1echo将docker目录下所有文件复制到/usr/bin目录cpdocker/* /usr/binecho将docker.service 复制到/etc/systemd/system/目录cpdocker.service /etc/systemd/system/echo添加文件可执行权限chmodx /etc/systemd/system/docker.serviceecho重新加载配置文件systemctl daemon-reloadecho启动dockersystemctl startdockerecho设置开机自启systemctlenabledocker.serviceechodocker安装成功docker-v新建 docker 卸载脚本 docker-uninstall.shtouchdocker-uninstall.sh编辑 docker-uninstall.sh内容如下#!/bin/shecho停止dockersystemctl stopdockerecho删除docker.servicerm-f/etc/systemd/system/docker.serviceecho删除docker文件rm-rf/usr/bin/docker*echo重新加载配置文件systemctl daemon-reloadecho卸载成功赋予 脚本可执行权限。chmodx docker-install.shchmodx docker-uninstall.sh执行 脚本安装 dockersh docker-install.sh docker-26.1.0.tgz查看docker状态systemctl statusdocker四、离线安装 docker-composeDocker Compose是一个用于定义和运行多容器Docker应用程序的工具。它采用YAML文件来配置应用程序的服务然后使用一个命令就可以启动并运行配置中的所有服务。通过Docker Compose用户无需手动逐个启动容器而是可以通过一个简单的配置文件来管理复杂的多容器应用程序。1. 下载docker-compose官方地址 https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-linux-x86_642. 安装将 docker-compose-linux-x86_64 文件上传到 /root 目录执行下列命令#移动文件到/usr/local/bin/并重命名为docker-composesudomv/root/docker-compose-linux-x86_64 /usr/local/bin/docker-compose#赋予docker-compose 可执行权限。sudochmodx /usr/local/bin/docker-compose#查看版本 docker-compose versiondocker-compose-v

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价