On AWS Lightsail, I am trying to establish communication between the backend and the database containers.
Here is my setup:
However, the result is different from my test on the local machine.
docker-compose.yml
on local machine:
version: '3.8'
services:
database:
image: mongo:latest
container_name: mongo_database
environment:
MONGO_INITDB_ROOT_USERNAME: username
MONGO_INITDB_ROOT_PASSWORD: password123
ports:
- "27017:27017"
networks:
- backend_network
backend:
image: custom_backend:latest
container_name: backend_service
environment:
MONGO_URI: mongodb://username:password123@database:27017/
ports:
- "4000:4000"
depends_on:
- database
networks:
- backend_network
networks:
backend_network:
driver: bridge
This setup runs successfully on my local machine.
Lightsail’s backend log
(ERROR):
[8/Jul/2024:15:00:15] [deployment:1] Creating your deployment
[8/Jul/2024:15:01:21] Running the application...
[8/Jul/2024:15:01:49] [deployment:1] Started 1 new node
[8/Jul/2024:15:02:45] Running the application...
[8/Jul/2024:15:03:25] [deployment:1] Health checks failed: port 4000 is unhealthy
[8/Jul/2024:15:03:46] make: *** [Makefile:3: run] Terminated
[8/Jul/2024:15:04:58] [deployment:1] Took too long
[8/Jul/2024:15:06:01] make: *** [Makefile:3: run] Terminated
localhost’s log (SUCCEED):
backend$ docker compose logs backend
backend_service | Running the application...
backend_service | INFO 2024/07/08 15:30:48 Starting server on http://localhost:4000
backend_service | 2024/07/08 15:30:50 [0165dc51d9d0/fprkUHXqaT-000001] "GET http://localhost:4000/ HTTP/1.1" from 172.18.0.1:36804 - 200 25B in 35.389µs
I also see no networks
or depends_on
options on Lightsail. I am not sure if that is causing this issue, but I couldn’t find those configurations on the Lightsail dashboard.