Reputation: 3559
I am successfully able to connect the servicebot service to the postgresql running within the docker container but I want to connect the servicebot to the postgresql running in instance ie not inside docker container.
I have installed the postgresql successfully. I have set the environment variables related to postgrsql in the docker-compose.yml as bellow. How can I make the docker-compose.yml connect to the
docker-compose.yml
version: '2'
services:
servicebot:
image: servicebot/servicebot
environment:
POSTGRES_DB_PORT : "5432"
POSTGRES_DB_HOST : "localhost"
POSTGRES_DB_USER : "servicebot_user"
POSTGRES_DB_PASSWORD : "servicebot_pass"
POSTGRES_DB_NAME : "servicebot_user"
PORT : "3000"
volumes:
- upload-data:/usr/src/app/uploads
- environment-file:/usr/src/app/env
- db-data:/var/lib/postgresql/data
# links:
# - db
ports:
- "80:3000"
- "443:3001"
command: ["sh", "-c", "node /usr/src/app/bin/wait-for-it.js db 5432 && npm run-script start"]
volumes:
upload-data:
environment-file:
db-data:
Previously I had a service named db for postgresql and connected to it with links as you can see, I have commented that out now.
I am very new to postgresql and not able to figure out the right way. I have tried few ways but nothing came to my success.
Tried:
Adding extra_hosts
to the ip if the instance
Adding host.docker.internal
instead of localhost
Error Logs:
On
docker logs servicename
It does not show anything. The service stops after 29 30 seconds.
Upvotes: 1
Views: 3562
Reputation: 332
Just a heads up that if you're running Docker
on a MAC (macOS), you need to use: docker.for.mac.host.internal
instead.
Upvotes: 1
Reputation: 5658
Your problem is POSTGRES_DB_HOST
pointing to "localhost", as "localhost" will be the container running your current service.
If you want to connect to a postgre running in your host (localhost) I think you can use this special value host.docker.internal
.
Upvotes: 4