离线环境安装docker

下载离线包

https://download.docker.com/linux/static/stable/x86_64/docker-27.1.0.tgz

安装

# 解压
tar -zxvf docker-27.1.0.tgz

mv docker/* /usr/local/bin/

# 赋权限
chmod +x /usr/local/bin/docker-init
chmod +x /usr/local/bin/runc
chmod +x /usr/local/bin/containerd-shim-runc-v2
chmod +x /usr/local/bin/ctr
chmod +x /usr/local/bin/docker
chmod +x /usr/local/bin/dockerd
chmod +x /usr/local/bin/containerd
chmod +x /usr/local/bin/docker-proxy

#建立软连接
ln -s /usr/local/bin/docker-init /usr/bin/docker-init
ln -s /usr/local/bin/runc /usr/bin/runc
ln -s /usr/local/bin/containerd-shim-runc-v2 /usr/bin/containerd-shim-runc-v2
ln -s /usr/local/bin/ctr /usr/bin/ctr
ln -s /usr/local/bin/docker /usr/bin/docker
ln -s /usr/local/bin/dockerd /usr/bin/dockerd
ln -s /usr/local/bin/containerd /usr/bin/containerd
ln -s /usr/local/bin/docker-proxy /usr/bin/docker-proxy

添加docker用户组(存在则跳过)

groupadd docker

Docker 的 systemd 服务文件

下载 Docker 的 systemd 服务文件,也可使用后续步骤进行创建。

#下载 Docker 的 systemd 服务文件,也可使用后续步骤进行创建
https://raw.githubusercontent.com/moby/moby/master/contrib/init/systemd/docker.service

https://raw.githubusercontent.com/moby/moby/master/contrib/init/systemd/docker.target

#下载 containerd 的 systemd 服务文件,也可使用后续步骤进行创建
https://raw.githubusercontent.com/containerd/containerd/main/containerd.service

docker.service

创建/etc/systemd/system/docker.service,内容如下:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
# Requires=docker.socket

[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
TimeoutStartSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# 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
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

修改权限:

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

containerd.service

创建/etc/systemd/system/containerd.service,内容如下:

# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target

修改文件权限:

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

启动docker

systemctl daemon-reload 

systemctl enable containerd
systemctl start containerd

systemctl enable docker
systemctl start docker

安装docker-compose

https://github.com/docker/compose/releases下载docker-compose-linux-x86_64,下载完成后,移动至/usr/local/bin目录下

mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
# 修改权限
sudo chmod +x /usr/local/bin/docker-compose

在容器中使用英伟达驱动

前提条件

  • 主机已安装英伟达驱动、CUDA-Toolkit等相关软件;
  • 一台联网电脑

下载nvidia-container-toolkit

curl -s -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo | sudo tee /etc/yum.repos.d/nvidia-container-toolkit.repo

sudo yum-config-manager --enable nvidia-container-toolkit-experimental

sudo yum install --downloadonly --downloaddir=/root/mypackages/ nvidia-container-toolkit #该命令会下载nvidia-container-toolkit及其依赖

安装nvidia-container-toolkit

由于存在依赖关系建议使用以下顺序进行安装:

sudo yum install libnvidia-container1-1.13.5-1.x86_64.rpm -y
sudo yum install libnvidia-container-tools-1.13.5-1.x86_64.rpm -y
sudo yum install nvidia-container-toolkit-base-1.13.5-1.x86_64.rpm -y
sudo yum install nvidia-container-toolkit-1.13.5-1.x86_64.rpm -y
sudo nvidia-ctk runtime configure --runtime=docker

sudo systemctl daemon-reload
sudo systemctl restart docker

问题

driver rpc error: timed out

如果出现nvidia-container-cli: initialization error: driver rpc error: timed out问题,使用以下命令开启gpu持续模式:

nvidia-smi -pm ENABLED
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

great-wind

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值