docker compose 安装
docker-compose:
指的是在单机节点上批量管理一组容器的方法,目前比较主流的单机编排工具是"docker-compose"。
如上图所示,是docker版本和docker-comopse的对应关系。
推荐阅读:
https://docs.docker.com/compose/compose-file/
https://docs.docker.com/compose/compose-file/compose-versioning/
三种安装docker-compose方式:
(1)使用epel源直接安装(缺点就是版本较低,docker-compose version 1.18.0,)
# yum -y install epel-release
# yum -y install docker-compose
(2)给docker打补丁安装(先安装docker,再docker compose补丁,一般情况是最新版本)
curl -s -o /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
yum -y install docker-compose-plugin
vim /root/.bashrc
...
alias docker-compose='docker compose'
source /root/.bashrc
# yum -y remove docker-compose-plugin # 卸载软件
白眉大叔用这种方式安装的。
docker-compose 升级
如果遇到这样的问题,就需要升级了
ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
whereis docker-compose
/usr/bin/docker-compose
根据上一步的whereis
找到了docker-compose的路径为:/usr/bin/docker-compose
,所以下面的脚本,路径也替换为这个就可以了。
下载一个
https://github.com/docker/compose/releases/
或直接下载centos地址
https://github.com/docker/compose/releases/download/v2.24.6/docker-compose-linux-x86_64
改名
mv docker-compose-linux-x86_64 docker-compose
chmod +x docker-compose
mv docker-compose /usr/bin/
检查
docker-compose version
(3)基于二进制安装(需要从GitHub下载软件包,不推荐!速度慢!)
curl -SL https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
参考链接:
https://docs.docker.com/compose/install/linux/
https://docs.docker.com/compose/install/other/
GitHub加速地址: (慎入哟,尤其是需要登录时不建议使用,公开的项目是可以下载的!)
https://hub.nuaa.cf/
https://ghproxy.com
https://hub.nuaa.cf/
https://ghproxy.com
自定义脚本安装: 推荐:
sh install-docker.sh install
这个脚本可以 实现 docker 和 docker-cojmpose 的安装
docker and docker-compose install binary: https://url69.ctfile.com/d/253469-56495921-56a066?p=2206 (访问密码: 2206)
install-docker.sh 内容:
#!/bin/bash
# auther: baimei
# 官网地址: www.baimeidashu.com
# DOCKER_VERSION=24.0.2
DOCKER_VERSION=20.10.24
# DOCKER_VERSION=19.03.15
# DOCKER_COMPOSE_VERSION=2.17.3
DOCKER_COMPOSE_VERSION=2.18.1
FILENAME=docker-${DOCKER_VERSION}.tgz
DOCKER_COMPOSE_FILE=docker-compose-v${DOCKER_COMPOSE_VERSION}
URL=https://download.docker.com/linux/static/stable/x86_64
# DOCKER_COMPOSE_URL=https://github.com/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/docker-compose-linux-x86_64
DOCKER_COMPOSE_URL=https://hub.nuaa.cf/docker/compose/releases/download/v${DOCKER_COMPOSE_VERSION}/docker-compose-linux-x86_64
DOWNLOAD=./download
BASE_DIR=/baimei/softwares
# 判断是否下载了docker-compose
function prepare(){
# 判断是否下载docker-compose文件
if [ ! -f ${DOWNLOAD}/${DOCKER_COMPOSE_FILE} ]; then
wget -T 3 -t 2 ${DOCKER_COMPOSE_URL} -O ${DOWNLOAD}/${DOCKER_COMPOSE_FILE}
fi
if [ $? != 0 ];then
rm -f ${DOWNLOAD}/${DOCKER_COMPOSE_FILE}
echo "不好意思,由于网络波动原因,无法下载${DOCKER_COMPOSE_URL}软件包,程序已退出!请稍后再试......"
exit 100
fi
# 给脚本添加执行权限
chmod +x ${DOWNLOAD}/${DOCKER_COMPOSE_FILE}
}
# 定义安装函数
function InstallDocker(){
# 判断文件是否存在,若不存在则下载软件包
if [ ! -f ${DOWNLOAD}/${FILENAME} ]; then
wget ${URL}/${FILENAME} -O ${DOWNLOAD}/${FILENAME}
fi
# 判断解压路径是否存在
if [ ! -d ${BASE_DIR} ]; then
install -d ${BASE_DIR}
fi
# 解压软件包到指定目录
tar xf ${DOWNLOAD}/${FILENAME} -C ${BASE_DIR}
# 安装docker-compose
prepare
cp $DOWNLOAD/${DOCKER_COMPOSE_FILE} ${BASE_DIR}/docker/docker-compose
# 创建软连接
ln -svf ${BASE_DIR}/docker/* /usr/bin/
# 自动补全功能
cp $DOWNLOAD/docker /usr/share/bash-completion/completions/docker
source /usr/share/bash-completion/completions/docker
# 配置镜像加速
install -d /etc/docker
cp $DOWNLOAD/daemon.json /etc/docker/daemon.json
# 开机自启动脚本
cp download/docker.service /usr/lib/systemd/system/docker.service
systemctl daemon-reload
systemctl enable --now docker
docker version
docker-compose version
tput setaf 3
echo "安装成功,欢迎使用白眉大叔二进制docker安装脚本,欢迎下次使用!---> www.baimeidashu.com"
tput setaf 2
}
# 卸载docker
function UninstallDocker(){
# 停止docker服务
systemctl disable --now docker
# 卸载启动脚本
rm -f /usr/lib/systemd/system/docker.service
# 清空程序目录
rm -rf ${BASE_DIR}/docker
# 清空数据目录
rm -rf /var/lib/{docker,containerd}
# 清除符号链接
rm -f /usr/bin/{containerd,containerd-shim,containerd-shim-runc-v2,ctr,docker,dockerd,docker-init,docker-proxy,runc}
# 使得终端变粉色
tput setaf 5
echo "卸载成功,欢迎再次使用白眉大叔二进制docker安装脚本哟~ ----> www.baimeidashu.com"
tput setaf 7
}
# 程序的入口函数
function main(){
# 判断传递的参数
case $1 in
"install")
InstallDocker
;;
"remove")
UninstallDocker
;;
*)
echo "Invalid parameter, Usage: $0 install|remove"
;;
esac
}
# 向入口函数传参
main $1
检查:
说明 成功安装
docker and docker-compose install binary: https://url69.ctfile.com/d/253469-56495921-56a066?p=2206 (访问密码: 2206)
欢迎来撩 : 汇总all