docker相关
大约 3 分钟
安装
准备文件
bash install_docker.sh
#!/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
目录(其他目录均可)下,步骤如下:
# 停止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镜像
docker pull <image_name>:<tag>
保存下载的docker镜像为压缩文件
docker save -o image_file.tar <image_name>:<tag>
docker save -o milvus.tar milvusdb/milvus:v2.4.1
将压缩文件传输到目标服务器
scp image_file.tar user@target_server_ip:/path/to/destination_folder
在目标服务器上操作
加载离线的docker镜像
docker load -i /path/to/destination_folder/image_file.tar
Docker使用第三方源
下载
docker pull m.daocloud.io/docker.io/qdrant/qdrant:v1.9.7
改tag
docker tag m.daocloud.io/docker.io/qdrant/qdrant:v1.9.7 qdrant/qdrant:v1.9.7
删除源镜像
docker rmi m.daocloud.io/docker.io/qdrant/qdrant:v1.9.7
运行
docker run -p -d 6333:6333 --name qdrant qdrant/qdrant:v1.9.7