I am using AWS ECS and have a container for my frontend (Node app) and for my backend (mongo database).
The mongo container is exposing port 27017, but I cannot figure out how to connect to it from my frontend container. If I try to connect to the db using 'mongodb://localhost:27017/db_name' I get an ECONNREFUSED error.
I have a service running for both of these task definitions with an ALB for the frontend. I don't have them in the same task definition because it doesn't seem optimal to have to scale them together.
I have tried multiple variations of the url
- mongodb://0.0.0.0:27017/db_name
- mongodb://localhost:27017/db_name
If I "curl" the mongo container from within the EC2 instance, I get an empty reply from server.
Database Task Definition:
{
"executionRoleArn": null,
"containerDefinitions": [
{
"dnsSearchDomains": null,
"logConfiguration": null,
"entryPoint": null,
"portMappings": [
{
"hostPort": 27017,
"protocol": "tcp",
"containerPort": 27017
}
],
"command": null,
"linuxParameters": null,
"cpu": 0,
"environment": [
{
"name": "MONGODB_ADMIN_PASS",
"value": <PASSWORD>
},
{
"name": "MONGODB_APPLICATION_DATABASE",
"value": <DB NAME>
},
{
"name": "MONGODB_APPLICATION_PASS",
"value": <PASSWORD>
},
{
"name": "MONGODB_APPLICATION_USER",
"value": <USERNAME>
}
],
"ulimits": null,
"dnsServers": null,
"mountPoints": [],
"workingDirectory": null,
"dockerSecurityOptions": null,
"memory": null,
"memoryReservation": 128,
"volumesFrom": [],
"image": "registry.hub.docker.com/library/mongo:latest",
"disableNetworking": null,
"healthCheck": null,
"essential": true,
"links": null,
"hostname": null,
"extraHosts": null,
"user": null,
"readonlyRootFilesystem": null,
"dockerLabels": null,
"privileged": null,
"name": "mongo"
}
],
"placementConstraints": [],
"memory": null,
"taskRoleArn": null,
"compatibilities": [
"EC2"
],
"taskDefinitionArn": "arn:aws:ecs:us-east-2:821819063141:task-definition/dappy_coin_database:2",
"family": "dappy_coin_database",
"requiresAttributes": [
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
}
],
"requiresCompatibilities": null,
"networkMode": null,
"cpu": null,
"revision": 2,
"status": "ACTIVE",
"volumes": []
}