I have a postgresql server configured with docker-compose :
version: "3"
services:
heritagebuxfr-postgres:
image: postgres:12
environment:
- POSTGRES_DB=heritagebuxfr
- POSTGRES_USER=heritagebuxfr
- POSTGRES_PASSWORD=xxxxxxxx
restart: always
volumes:
- /data/heritagebuxfr-posgtres:/var/lib/postgresql/data
networks:
heritagebuxfr:
ipv4_address: 10.8.0.5
networks:
heritagebuxfr:
driver: bridge
ipam:
config:
- subnet: 10.8.0.0/16
When I try to connect it, it fail. Example :
docker run -it --rm --network root_heritagebuxfr postgres psql -h heritagebuxfr-postgres -U heritagebuxfr
psql: error: connection to server at "heritagebuxfr-postgres" (10.8.0.5), port 5432 failed: Connection timed out
Is the server running on that host and accepting TCP/IP connections?
How to configure my postgresql container or other container to be able to acceded ?
Below, some additional information :
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5543d6f43a00 algoo/tracim:4.4.2 "/bin/bash /tracim/t…" 12 hours ago Up About a minute 0.0.0.0:10088->80/tcp, :::10088->80/tcp root_heritagebuxfr_1
28739c1d135a postgres:12 "docker-entrypoint.s…" 12 hours ago Up 12 hours 5432/tcp root_heritagebuxfr-postgres_1
[...]
docker network ls
root@s2:~# docker network ls
NETWORK ID NAME DRIVER SCOPE
924e62e9349c bridge bridge local
d82517c5bf4a host host local
0a94208c6a9c none null local
794be35c7046 prestashop-net bridge local
3c718488b040 root_default bridge local
f3dafc20a876 root_dentiste74fr bridge local
3be74184dda3 root_heritagebuxfr bridge local
41db94bb460a root_muzich bridge local
4c1fc0c30383 root_rocketchatmah bridge local
0537f6c1667f root_tracimbuxfr bridge local
iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
DOCKER-USER all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-1 all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain DOCKER (8 references)
target prot opt source destination
ACCEPT tcp -- anywhere 172.18.0.2 tcp dpt:9980
ACCEPT tcp -- anywhere 10.5.0.6 tcp dpt:http
ACCEPT tcp -- anywhere 10.7.0.4 tcp dpt:http
ACCEPT tcp -- anywhere 10.7.0.4 tcp dpt:3030
ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:http
ACCEPT tcp -- anywhere 172.18.0.3 tcp dpt:3000
ACCEPT tcp -- anywhere 172.18.0.3 tcp dpt:ssh
ACCEPT tcp -- anywhere 10.6.0.6 tcp dpt:http
ACCEPT tcp -- anywhere 172.18.0.4 tcp dpt:http-alt
ACCEPT tcp -- anywhere 172.18.0.5 tcp dpt:8082
ACCEPT tcp -- anywhere 172.18.0.5 tcp dpt:https
ACCEPT tcp -- anywhere 172.18.0.5 tcp dpt:http
ACCEPT tcp -- anywhere 10.8.0.4 tcp dpt:http
Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target prot opt source destination
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
RETURN all -- anywhere anywhere
Chain DOCKER-ISOLATION-STAGE-2 (8 references)
target prot opt source destination
DROP all -- anywhere anywhere
DROP all -- anywhere anywhere
DROP all -- anywhere anywhere
DROP all -- anywhere anywhere
DROP all -- anywhere anywhere
DROP all -- anywhere anywhere
DROP all -- anywhere anywhere
DROP all -- anywhere anywhere
RETURN all -- anywhere anywhere
Chain DOCKER-USER (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
docker network inspect root_heritagebuxfr
[
{
"Name": "root_heritagebuxfr",
"Id": "3b9d353561a02dd9bea8bbc66258aa120fbd464cf8fb519c4b47ed9f82110d8e",
"Created": "2022-11-15T10:27:39.751614908Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "10.8.0.0/16"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"673decc2a8a4493fbdb01000684ed0e8f42905bea200e6efc412bd55f27fcca1": {
"Name": "root-heritagebuxfr-postgres-1",
"EndpointID": "35d0cd973c79758c242b9510e475e827b5c7aa6633aedb3daa655147ae89668f",
"MacAddress": "02:42:0a:08:00:05",
"IPv4Address": "10.8.0.5/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "heritagebuxfr",
"com.docker.compose.project": "root",
"com.docker.compose.version": "2.12.2"
}
}
]
root@s2:~# docker --version
Docker version 20.10.21, build baeda1f
root@s2:~# docker-compose --version
docker-compose version 1.21.2, build a133471
$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
Note: I read all stack overflow answer about with subject but no one works for this configuration.