写点什么

Linux 中安装 / 部署 docker-compose

作者:A-刘晨阳
  • 2022-11-22
    北京
  • 本文字数:3388 字

    阅读完需:约 11 分钟

前提

必须要有 docker,如果没有可以去查看:linux(centos)中部署docker(步骤超全,含带一些发展史和一些概念),有安装步骤。


两种安装/部署方式

第一种:按照官方文档下载 docker-compose 包来安装

(1)下载 docker-compose

执行如下命令进行下载


curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
复制代码


若速度较慢,可以使用如下命令:


curl -L "https://mirror.ghproxy.com/https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
复制代码

(2)修改目录权限

chmod  x /usr/local/bin/docker-compose
复制代码

(3)创建软连接

ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
复制代码

(4)验证安装是否完成

执行如下命令,如果可以正常显示版本号,则表示已经完成


docker-compose --version
复制代码


第二种:使用 pip install 的方式安装

因为 docker-compose 是使用 python 开发的,因此可以通过 pip install 的方式安装

(1)首先需要确保 pip 已经安装完成,如下

如下,表示 pip 为基于 python3.9 的版本,这里最好安装基于 python3.6 以上的 pip


这里有安装文档:Linux下安装Python3.6.8(超级详细),可以采纳。


[root@localhost ~]# pip3 --versionpip 21.2.4 from /usr/local/python3/lib/python3.9/site-packages/pip (python 3.9)
复制代码

(2)升级 pip 的版本

python3 -m pip install --upgrade pip
复制代码


如:


[root@localhost ~]# python3 -m pip install --upgrade pipLooking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/Requirement already satisfied: pip in /usr/local/python3/lib/python3.9/site-packages (21.2.4)Collecting pip  Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl (1.7 MB)     |████████████████████████████████| 1.7 MB 105 kB/sInstalling collected packages: pip  Attempting uninstall: pip    Found existing installation: pip 21.2.4    Uninstalling pip-21.2.4:      Successfully uninstalled pip-21.2.4  WARNING: The scripts pip, pip3 and pip3.9 are installed in '/usr/local/python3/bin' which is not on PATH.  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.Successfully installed pip-21.3.1WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
复制代码

(3)安装 docker-compose

pip3 install docker-compose
复制代码


如下:


[root@localhost ~]# pip3 install docker-composeLooking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/Requirement already satisfied: docker-compose in /usr/local/python3/lib/python3.9/site-packages (1.29.2)Requirement already satisfied: docker[ssh]>=5 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (5.0.3)Requirement already satisfied: PyYAML<6,>=3.10 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (5.4.1)Requirement already satisfied: jsonschema<4,>=2.5.1 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (3.2.0)Requirement already satisfied: python-dotenv<1,>=0.13.0 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (0.19.1)Requirement already satisfied: texttable<2,>=0.9.0 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (1.6.4)Requirement already satisfied: websocket-client<1,>=0.32.0 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (0.59.0)Requirement already satisfied: distro<2,>=1.5.0 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (1.6.0)Requirement already satisfied: docopt<1,>=0.6.1 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (0.6.2)Requirement already satisfied: dockerpty<1,>=0.4.1 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (0.4.1)Requirement already satisfied: requests<3,>=2.20.0 in /usr/local/python3/lib/python3.9/site-packages (from docker-compose) (2.26.0)Requirement already satisfied: paramiko>=2.4.2 in /usr/local/python3/lib/python3.9/site-packages (from docker[ssh]>=5->docker-compose) (2.8.0)Requirement already satisfied: six>=1.3.0 in /usr/local/python3/lib/python3.9/site-packages (from dockerpty<1,>=0.4.1->docker-compose) (1.16.0)Requirement already satisfied: attrs>=17.4.0 in /usr/local/python3/lib/python3.9/site-packages (from jsonschema<4,>=2.5.1->docker-compose) (21.2.0)Requirement already satisfied: pyrsistent>=0.14.0 in /usr/local/python3/lib/python3.9/site-packages (from jsonschema<4,>=2.5.1->docker-compose) (0.18.0)Requirement already satisfied: setuptools in /usr/local/python3/lib/python3.9/site-packages (from jsonschema<4,>=2.5.1->docker-compose) (57.4.0)Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/python3/lib/python3.9/site-packages (from requests<3,>=2.20.0->docker-compose) (1.26.6)Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/python3/lib/python3.9/site-packages (from requests<3,>=2.20.0->docker-compose) (2.0.7)Requirement already satisfied: idna<4,>=2.5 in /usr/local/python3/lib/python3.9/site-packages (from requests<3,>=2.20.0->docker-compose) (3.3)Requirement already satisfied: certifi>=2017.4.17 in /usr/local/python3/lib/python3.9/site-packages (from requests<3,>=2.20.0->docker-compose) (2021.5.30)Requirement already satisfied: cryptography>=2.5 in /usr/local/python3/lib/python3.9/site-packages (from paramiko>=2.4.2->docker[ssh]>=5->docker-compose) (35.0.0)Requirement already satisfied: pynacl>=1.0.1 in /usr/local/python3/lib/python3.9/site-packages (from paramiko>=2.4.2->docker[ssh]>=5->docker-compose) (1.4.0)Requirement already satisfied: bcrypt>=3.1.3 in /usr/local/python3/lib/python3.9/site-packages (from paramiko>=2.4.2->docker[ssh]>=5->docker-compose) (3.2.0)Requirement already satisfied: cffi>=1.1 in /usr/local/python3/lib/python3.9/site-packages (from bcrypt>=3.1.3->paramiko>=2.4.2->docker[ssh]>=5->docker-compose) (1.15.0)Requirement already satisfied: pycparser in /usr/local/python3/lib/python3.9/site-packages (from cffi>=1.1->bcrypt>=3.1.3->paramiko>=2.4.2->docker[ssh]>=5->docker-compose) (2.20)WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
复制代码

(4)验证是否安装完成

docker-compose -version
复制代码


如下


[root@localhost ~]# docker-compose -versiondocker-compose version 1.29.2, build unknown
复制代码

总结

相关文章:


①、Docker——denied: requested access to the resource is denied问题以及解决方法②、Docker搭建harbor私有镜像仓库(命令行模式)③、Linux中基于Docker搭建harbor私有镜像仓库(超级详细)🔥🔥④、Docker发布/上传镜像到dockerhub&&下载/拉取镜像&&删除dockerhub镜像


发布于: 刚刚阅读数: 4
用户头像

A-刘晨阳

关注

还未添加个人签名 2022-06-16 加入

本人公众号《小刘Linux》,优质博主,欢迎大家的关注

评论

发布
暂无评论
Linux中安装/部署docker-compose_Docker_A-刘晨阳_InfoQ写作社区