0

I have a docker 17.05.0-ce, build 89658be on ubuntu server 16.04 LTS. I have a Postgres running in a container and exposing port 5432.

I can connect it from anywhere except a sibling container where psql just timeouts. As address, I use the host's IP. Ping from client works, psql connect doesn't.

I know I could create a docker-compose with combined Postgres service, but would rather not - I want to keep them totally separate.

Any idea how to troubleshoot the problem?

0

3 Answers 3

1

You have to put both container on the same docker network for them to able to talk to each other.

docker network create funny

Then start your container attaching to the network

docker run database_container --net=funny --name=database

docker run app_container --net=funny --name=app

Once you do that, you can connect to each container by the name you specify in the run command.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, I ended doing that at the end. Thanks.
0

You want use --net=host for that.

Adding the answer I got for a similar question:

For a quick work around you can run all the containers with flag --net=host which means the docker containers will use the host network interface. more info on docker networking can be found here.

1 Comment

That might work but at the end the traefik won't play nicely with it. Good though though.
0

Pass -c 'listen_addresses=*' to docker run command line this will allow postgress to accept connection from remote machine:

docker run --name postgres -p 5432:5432  -ePOSTGRES_DB=pgdb -e POSTGRES_USER=user -e POSTGRES_PASSWORD=pass -d postgres -c 'listen_addresses=*'

3 Comments

I had problem connecting from a sibling container, not remote machine.
your sibling is also remote if not in the same network, it will work with docker compose because docker compose creates a network. if you want to go without compose then you have to update listen_addresses as suggested. does it make sense?
I'm using compose. Anyway, placing both containers into the same network seems the cleanest and best option to me. Thanks anyway for suggestion.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.