I'm working with a containerized Laravel app that is supposed to be connecting to a remote rds database, here is a sample .env
DB_HOST=xxxxxx.rds.amazonaws.com
DB_DATABASE=sample
DB_USERNAME=sample
DB_PASSWORD=sample
DB_PORT=3306
DATABASE_DRIVER=mysql
The container works as it should but the problem is, it cannot connect to the remote rds database, when I try running composer ie:
$ docker exec -ti laravel-php bash
$ composer install
I get this error:
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'sample'@'192.168.66.1' (using password: YES)
Script php artisan clear-compiled handling the post-install-cmd event returned with error code 1
192.168.66.1 as my docker container's ip, I suspect that the db policy is open via @localhost access since my dev ops confirmed that it's open for public connections.
I'm using docker-compose version 2 btw, here's a sample docker-compose:
version: '2'
services:
sample-server:
build:
context: ./
dockerfile: sample.server.docker
volumes:
- ../backend:/var/www
ports:
- "8081:80"
environment:
- VIRTUAL_HOST=sample.local
links:
- sample-php
depends_on:
- sample-php
sample-php:
build:
context: ./
dockerfile: sample.php.docker
volumes:
- .:/var/www
links:
- sample-database
environment:
- "DB_PORT=3306"
- "DB_HOST=sample-database"
sample-database:
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=samplepassword"
- "MYSQL_DATABASE=sample"
ports:
- "33081:3306"
sample-nginx-proxy:
image: jwilder/nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
networks:
default:
external:
name: sample-nginx-proxy
How can I fix this?