Container in error state in my ECS Task

0

Hello, I tried to run 6 containers from a docker compose in ECS task. I have 4 containers that run normally but they are 2 that does not run because of two errors:

  1. Unknown MySQL server host 'mysql' even if i have the value in variables environments
  2. 15:27:55 CRITICAL [console] Error thrown while running command "doctrine:migrations:migrate -n -e prod". Message: "An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known" ["exception" => Doctrine\DBAL\Exception\ConnectionException { …},"command" => "doctrine:migrations:migrate -n -e prod","message" => "An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known"]. is anayone have an idea for this problem?
  • Can you clarify - are the containers that are running configured in same way as the 2 failed ones? Are these using same ecr docker image? Are these running in same subnet and have same security group?

asked 2 months ago53 views
1 Answer
0

It appears you're experiencing issues with container networking and database connectivity in your ECS task. Let's address each problem:

  1. Unknown MySQL server host 'mysql': This error suggests that your container is unable to resolve the hostname 'mysql'. In ECS, containers within the same task can communicate with each other using their service names as hostnames, but this requires proper configuration. Ensure that:
  • You have a container named 'mysql' in your task definition
  • The 'mysql' container is running and healthy
  • Your application is configured to use 'mysql' as the hostname for database connections
  • The necessary environment variables for database connection are correctly set in your task definition
  1. php_network_getaddresses: getaddrinfo failed: This error is similar to the first one and indicates a DNS resolution problem. It's likely that your application is unable to resolve the database hostname. To resolve this:
  • Double-check that the database hostname in your application's configuration matches the actual hostname or service name of your MySQL container
  • Ensure that your ECS task is using the awsvpc network mode, which provides each task with its own elastic network interface and IP address
  • Verify that your VPC's DNS settings are correct and that DNS resolution is functioning properly

Additional troubleshooting steps:

  • Review your task definition to ensure all necessary environment variables are correctly set
  • Check the logs of your MySQL container to ensure it's starting up correctly
  • Verify that your VPC and security group settings allow communication between your application containers and the MySQL container
  • Consider using the IP address of the MySQL container instead of its hostname as a temporary workaround
  • If you're using Fargate, make sure your task has the required permissions to access other AWS resources if needed

If the issue persists after checking these points, you may need to examine your application's database connection code and ensure it's compatible with the ECS networking model.
Sources
Intermittent error when accessing RDS database with PHP 7.4 | AWS re:Post
Connection issues - Amazon DocumentDB

profile picture
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions