在我的开发环境中,我想模拟一个“ Web场”部署,其中有几个运行多个服务的“物理”节点,这些服务属于同一网络。
因此,假设我有5个节点,每个节点将托管1个mysql
,1个nginx
和2个web
应用程序。并且mysql
将绑定到相同的端口3306
,但绑定到不同的IP地址。
我开始写下docker-compose
配置,并停留在第一步:Docker拒绝在给定的网络中创建新的IP,并将mysql绑定到该IP上的端口。
这是我要使用的配置:
version: "3"
services:
node1_sql:
image: mariadb:10.0.33
restart: always
networks:
skkb:
ipv4_address: 10.9.2.2
ports:
- 10.9.2.2:3306:3306
environment:
- MYSQL_DATABASE=dbname
- MYSQL_ROOT_PASSWORD=password
volumes:
- ./sql_data/1:/var/lib/mysql
command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci
networks:
skkb:
driver: bridge
ipam:
driver: default
config:
- subnet: 10.9.2.0/24
当我尝试做docker-compose up
时,出现以下错误:
Creating network "node-r_skkb" with driver "bridge"
Creating node-r_node1_sql_1 ... error
ERROR: for node-r_node1_sql_1 Cannot start service node1_sql: driver failed programming external connectivity on endpoint node-r_node1_sql_1 (24a8412b80ebc95f5b15f5d4ea5281639d6914f312f525cf8803ed5179b906a7): Error starting userland proxy: listen tcp 10.9.2.2:3306: bind: cannot assign requested address
ERROR: for node1_sql Cannot start service node1_sql: driver failed programming external connectivity on endpoint node-r_node1_sql_1 (24a8412b80ebc95f5b15f5d4ea5281639d6914f312f525cf8803ed5179b906a7): Error starting userland proxy: listen tcp 10.9.2.2:3306: bind: cannot assign requested address
ERROR: Encountered errors while bringing up the project.
如果我尝试绑定到10.9.2.1
,则没有问题。因此在我看来,它无法创建配置为ipv4_address: 10.9.2.2
有什么解决办法吗?
答案 0 :(得分:0)
仅供测试,请重新启动Docker并再次检查