小言_互联网的博客

CentOS7中安装Docker-Compose

487人阅读  评论(0)

1. 前言


前段时间使用 Docker 部署了 SpringBoot 以及一些关联应用,不过都是单独部署的各个容器;如果项目需要部署到多套环境中,则每套环境中都需要重复性的启用容器并关联容器,这样的部署方式就显得很繁琐;于是在这种情况下,就可以使用到 Docker 三剑客之 Docker-Compose。

 

2. 用处


Docker-compose 实则就是把所有容器描述、端口映射、配置映射以及依赖关系等系列配置写在了一个配置文件中,也就好似一个批处理脚本,极大的提升了部署的速度。

 

3. 安装


3.1 安装 docker

CentOS7中安装Docker

3.2 安装 python-pip

---

查看 pip 版本

---

[root@cdy ~]# pip -V
-bash: /usr/bin/pip: No such file or directory

---

安装软件包

---

[root@cdy ~]# yum -y install epel-release
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution
... 省略部分 ...
  Verifying  : epel-release-7-11.noarch                                                                                                                                                             1/1
Installed:
  epel-release.noarch 0:7-11
Complete!

---

安装 pip

---

[root@cdy ~]# yum install python-pip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package python2-pip.noarch 0:8.1.2-5.el7 will be updated
---> Package python2-pip.noarch 0:8.1.2-10.el7 will be an update
--> Finished Dependency Resolution
... 省略部分 ...
Updated:
  python2-pip.noarch 0:8.1.2-10.el7
Complete!

---

升级 pip

---

[root@cdy ~]# pip install --upgrade pip
Collecting pip
  Downloading http://mirrors.aliyun.com/pypi/packages/30/db/9e38760b32e3e7f40cce46dd5fb107b8c73840df38f0046d8e6514e675a1/pip-19.2.3-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 76.6MB/s
Installing collected packages: pip
  Found existing installation: pip 8.1.2
    Uninstalling pip-8.1.2:
      Successfully uninstalled pip-8.1.2
Successfully installed pip-19.2.3

---

再次查看 pip 版本

---

[root@cdy ~]# pip -V
pip 19.2.3 from /usr/lib/python2.7/site-packages/pip (python 2.7)

3.3 安装 docker-compose

---

安装 docker-compose

---

[root@cdy ~]# pip install docker-compose
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting docker-compose
... 省略部分 ...
Successfully installed asn1crypto-0.24.0 backports.ssl-match-hostname-3.7.0.1 bcrypt-3.1.7 cached-property-1.5.1 cffi-1.12.3 cryptography-2.7 docker-3.7.3 docker-compose-1.24.1 docker-pycreds-0.4.0 dockerpty-0.4.1 docopt-0.6.2 enum34-1.1.6 functools32-3.2.3.post2 ipaddress-1.0.22 jsonschema-2.6.0 paramiko-2.6.0 pycparser-2.19 pynacl-1.3.0 six-1.12.0 texttable-0.9.1 websocket-client-0.56.0

---

查看 docker-compose 版本

---

[root@cdy ~]# docker-compose --version
/usr/lib/python2.7/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.2.1) doesn't match a supported version!
  RequestsDependencyWarning)
docker-compose version 1.24.1, build 4667896

---

最后看起来有一些版本不兼容问题,接下来卸载不兼容模块,重新安装

---

[root@cdy /]# pip uninstall urllib3
Uninstalling urllib3-1.22:
  /usr/lib/python2.7/site-packages/urllib3-1.22.dist-info/DESCRIPTION.rst
  /usr/lib/python2.7/site-packages/urllib3-1.22.dist-info/INSTALLER
  /usr/lib/python2.7/site-packages/urllib3-1.22.dist-info/METADATA
  /usr/lib/python2.7/site-packages/urllib3-1.22.dist-info/RECORD
  /usr/lib/python2.7/site-packages/urllib3-1.22.dist-info/WHEEL
  /usr/lib/python2.7/site-packages/urllib3-1.22.dist-info/metadata.json
  /usr/lib/python2.7/site-packages/urllib3-1.22.dist-info/top_level.txt
... 省略部分 ...

Proceed (y/n)? y
  Successfully uninstalled urllib3-1.22

[root@cdy /]# pip uninstall chardet
Uninstalling chardet-3.0.4:
  /usr/bin/chardetect
  /usr/lib/python2.7/site-packages/chardet-3.0.4.dist-info/DESCRIPTION.rst
  /usr/lib/python2.7/site-packages/chardet-3.0.4.dist-info/INSTALLER
  /usr/lib/python2.7/site-packages/chardet-3.0.4.dist-info/METADATA
  /usr/lib/python2.7/site-packages/chardet-3.0.4.dist-info/RECORD
  /usr/lib/python2.7/site-packages/chardet-3.0.4.dist-info/WHEEL
  /usr/lib/python2.7/site-packages/chardet-3.0.4.dist-info/entry_points.txt
  /usr/lib/python2.7/site-packages/chardet-3.0.4.dist-info/metadata.json
  /usr/lib/python2.7/site-packages/chardet-3.0.4.dist-info/top_level.txt
... 省略部分 ...

Proceed (y/n)? y
  Successfully uninstalled chardet-3.0.4

[root@cdy /]# pip install requests
Requirement already satisfied: requests in /usr/lib/python2.7/site-packages
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Downloading http://mirrors.aliyun.com/pypi/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 68.3MB/s
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python2.7/site-packages (from requests)
Collecting urllib3<1.23,>=1.21.1 (from requests)
  Downloading http://mirrors.aliyun.com/pypi/packages/63/cb/6965947c13a94236f6d4b8223e21beb4d576dc72e8130bd7880f600839b8/urllib3-1.22-py2.py3-none-any.whl (132kB)
    100% |████████████████████████████████| 133kB 62.6MB/s
Requirement already satisfied: idna<2.7,>=2.5 in /usr/lib/python2.7/site-packages (from requests)
Installing collected packages: chardet, urllib3
  Found existing installation: chardet 2.2.1
    Uninstalling chardet-2.2.1:
      Successfully uninstalled chardet-2.2.1
Successfully installed chardet-3.0.4 urllib3-1.22

---

再次查看 docker-compose 版本

---

[root@cdy /]# docker-compose --version
docker-compose version 1.24.1, build 4667896

 

4. 常用命令


  • 查看版本信息:docker-compose --version

以下命令需要在有 docker-compose.yaml 文件的目录下执行;在写法上与 docker 命令类似

  • 启动:docker-compose up -d
  • 停止:docker-compose stop
  • 停止并删除:docker-compose down
  • 查看构建的镜像:docker-compose images
  • 查看运行的容器:docker-compose ps -a

 

5. 扩展


CentOS7中常用命令行

舒适优雅的操作 Linux 客户端:MobaXterm

 

希望能够帮助到你

over

 

 

 


转载:https://blog.csdn.net/qq_41402200/article/details/101628965
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场