linux离线安装docker并启动

linux离线安装docker并启动

  1. 解压并移动到指定目录
bash 复制代码
# 查看压缩包内容(确认包含 docker/dockerd 等二进制文件)
tar -tzf docker-24.0.6.tgz
sudo cp /docker/* /usr/local/bin/
  1. 验证是否复制成功
bash 复制代码
# 验证二进制文件是否复制成功
ls -l /usr/local/bin/docker*  # 应看到 docker、dockerd、docker-proxy 等文件
  1. 配置docker所需的文件,其中ip地址和路径使用自己的
bash 复制代码
sudo vim /etc/systemd/system/docker.service
bash 复制代码
[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/local/bin/docker --selinux-enabled=false --insecure-registry=192.168.0.2
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
  1. 配置 containerd文件
bash 复制代码
sudo vim /etc/systemd/system/containerd.service
bash 复制代码
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Restart=always
RestartSec=5
Delegate=yes
KillMode=process
OOMScoreAdjust=-999
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity

[Install]
WantedBy=multi-user.target
  1. 创建这些东西
bash 复制代码
# 创建 Docker 数据目录(默认 /var/lib/docker,可自定义)
sudo mkdir -p /var/lib/docker
sudo mkdir -p /run/containerd
  1. 设置权限
bash 复制代码
# 赋予二进制文件执行权限	
sudo chmod +x /usr/local/bin/docker* /usr/local/bin/containerd* /usr/local/bin/runc

chmod 777 /etc/systemd/system/docker.service
  1. 准备启动
bash 复制代码
# 重新加载 systemd 配置
sudo systemctl daemon-reload

# 启动 containerd(先确保依赖正常)
sudo systemctl start containerd

# 启动 Docker
sudo systemctl start docker

# 检查 Docker 状态
sudo systemctl status docker
相关推荐
七歌杜金房7 小时前
我终于又有了自己的 Linux 电脑
linux·debian·mac
tntxia1 天前
linux curl命令详解_curl详解
linux
扛枪的书生1 天前
Linux 网络管理器用法速查
linux
顺风尿一寸2 天前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
lichenyang4532 天前
Docker 学习笔记(五):Docker Compose,用一个 YAML 启动前端、后端和 MongoDB
docker
lichenyang4532 天前
Docker 学习笔记(四):Dockerfile,把项目打成自己的镜像
docker·容器
lichenyang4532 天前
Docker 学习笔记(三):Docker 网络、bridge、子网和容器互通
docker·容器
lichenyang4532 天前
Docker 学习笔记(二):docker run 的参数到底在控制什么?
docker·容器
XIAOHEZIcode2 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
唐青枫2 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux