我似乎无法连接到AWS ECS中的MySQL容器。这是我用ecs-cli compose up
:
version: '2'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
logging:
driver: awslogs
options:
awslogs-group: "mylogs"
awslogs-region: "us-east-2"
awslogs-stream-prefix: "db"
mem_limit: 300000000
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: wordpress
logging:
driver: awslogs
options:
awslogs-group: "mylogs"
awslogs-region: "us-east-2"
awslogs-stream-prefix: "web"
mem_limit: 300000000
我得到的错误是:
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
这似乎在本地工作正常,但在AWS ECS中没有。我是否需要为AWS做其他事情?
答案 0 :(得分:0)
depends_on
字段为not supported in ECS。您的wordpress
容器在db
容器打开其端口之前启动,因此出错。
您需要引入一个包装器脚本来等待端口变为可用。