1:升级使用docker容器运行springboot项目时,springboot admin无法监控spring项目,报出RESTRICTED错误。查询原因springboot 项目注册到了docker内虚拟ip地址
2:nacos内设置ip可用spring.cloud.inetutils.preferred-networks 选择符合前缀的IP作为服务注册IP,但在docker内无法得到宿主服务器ip
3:找度娘查询找到可用Docker-Compose解决,记录使用情况
一:Docker-Compose介绍
Docker-Compose项目是Docker官方的开源项目,负责实现对Docker容器集群的快速编排。
Docker-Compose的使用步骤:
1:编写Dockerfile,导出镜像
Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
2:编写docker-compose.yml,管理镜像
Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
3:通过docker-compose运行镜像
Run docker compose up and the Docker compose command starts and runs your entire app. You can alternatively run docker-compose up using the docker-compose binary.
Docker-Compose将所管理的容器分为三层,分别是工程(project),服务(service)以及容器(container)
一个工程管理多个服务,一个服务管理多个容器实例。
Docker-Compose项目由Python编写,调用Docker服务提供的API来对容器进行管理。因此,只要所操作的平台支持Docker API,就可以在其上利用Compose来进行编排管理。
二:安装
1:以为通过pyhon-pip安装比较简单
apt install python-pip
pip install docker-compose
注:centos安装pip
yum -y install python-pip
安装
yum -y install epel-release
yum -y install python-pip
命令
pip install --upgrade pip
升级pip后,安装期间报错
=================================
File "/usr/bin/pip", line 9, in <module>
load_entry_point('pip==21.0.1', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
查看安装的版本
docker-compose --version
卸载
pip uninstall docker-compose
2:无奈到github网址下载编译好的二进制文件,也可curl直接下载
下载
官网:https://docs.docker.com/compose/install/
github网址:https://github.com/docker/compose/releases
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
添加可执行权限 chmod +x /usr/local/bin/docker-compose