Accessing RDS from within a Docker container not getting through security group?

前端 未结 5 2065
野性不改
野性不改 2020-12-13 10:29

I\'m attempting to run a webserver that uses an RDS database with EC2 inside a docker container.

I\'ve setup the security groups so the EC2 host\'s role is allowed

5条回答
  •  感情败类
    2020-12-13 11:06

    When I tried to connect to AWS RDS in inside of docker container, I got "Access denied for user 'username'@'xxx.xx.xxx.x' (using password: YES)" error. To solve this issue, I did below two ways:

    1. I created new user and assigned grant.

      $ CREATE USER 'newuser'@'%' IDENTIFIED BY 'password';
      $ GRANT ALL ON newuser@'%' IDENTIFIED BY  'password';
      $ FLUSH PRIVILEGES;
      
    2. Added global DNS address 8.8.8.8 into docker container when run docker, so that the docker container can resolve IP address of AWS RDS from domain name.

      $ docker run --name backend-app --dns=8.8.8.8 -p 8000:8000 -d backend-app
      

    Then I connected from inside of docker container to AWS RDS, successfully.

    • Note: Firstly, I tried second way. But I didn't solve the connection problem. When I tried both two ways, I was success.

提交回复
热议问题