目录

docker相关

安装

准备文件

./docker%E7%9B%B8%E5%85%B3.assets/image-20240628182400054.png

1
bash install_docker.sh
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
#!/bin/bash

# 作者: wjm
# 版本: 1.0
# 创建日期: 2024-05-23
# 描述: 这是一个运行 Python 脚本的 Bash 脚本,激活 conda 环境并在后台运行脚本。

echo "╔════════════════════════╗"
echo "║     你的脚本开始啦     ║"
echo "╚════════════════════════╝"

# 检查当前用户是否为root
if [ "$(whoami)" != "root" ]; then
    echo "需要root权限运行该脚本,请使用sudo或切换到root用户。"
    exit 1
fi

echo "开始安装 Docker..."

# 安装 Docker
tar -xvf docker-24.0.7.tgz
if [ $? -eq 0 ]; then
    echo "Docker安装成功"
else
    echo "Docker安装失败,请检查错误并解决问题"
    exit 1
fi

cp docker/* /usr/bin/

echo "设置 Docker 服务..."

# 将 Docker 设置为系统服务,并设置开机自启
cat > /usr/lib/systemd/system/docker.service <<'EOF'
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.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
TimeoutSec=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 location 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.
LimitNOFILE=infinity
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
EOF

systemctl daemon-reload
systemctl start docker
if [ $? -eq 0 ]; then
    echo "Docker服务已启动"
else
    echo "Docker服务启动失败,请检查错误并解决问题"
    exit 1
fi

systemctl status docker
echo "Docker服务已设置为开机自启"
systemctl enable docker

echo "安装 Docker Compose..."

# 安装 Docker Compose
cp docker-compose /usr/local/bin/docker-compose
if [ $? -eq 0 ]; then
    echo "Docker Compose安装成功"
else
    echo "Docker Compose安装失败,请检查错误并解决问题"
    exit 1
fi

chmod a+x /usr/local/bin/docker-compose
docker-compose -v

位置迁移

如果var/lib/docker的可用空间不足,可以考虑将Docker存储迁移到home目录(其他目录均可)下,步骤如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 停止Docker服务
sudo systemctl stop docker.service

# 迁移Docker数据目录
mv /var/lib/docker /home/docker

# 创建软链接
ln-s /home/docker /var/lib/docker

# 启动Docker服务
systemctl start docker.service

# 运行docker info来验证Docker是否正常运行,并查看存储路径是否已经更新
docker info

Docker离线

下载docker镜像

1
docker pull <image_name>:<tag>

保存下载的docker镜像为压缩文件

1
2
docker save -o image_file.tar <image_name>:<tag>
docker save -o milvus.tar milvusdb/milvus:v2.4.1

将压缩文件传输到目标服务器

1
scp image_file.tar user@target_server_ip:/path/to/destination_folder

在目标服务器上操作

加载离线的docker镜像

1
docker load -i /path/to/destination_folder/image_file.tar

Docker使用第三方源

下载

1
docker pull m.daocloud.io/docker.io/qdrant/qdrant:v1.9.7

改tag

1
docker tag m.daocloud.io/docker.io/qdrant/qdrant:v1.9.7 qdrant/qdrant:v1.9.7

删除源镜像

1
docker rmi m.daocloud.io/docker.io/qdrant/qdrant:v1.9.7

运行

1
docker run -p -d 6333:6333 --name qdrant qdrant/qdrant:v1.9.7