0

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.

5
  • from where do you want to connect to it? Commented Nov 14, 2022 at 20:20
  • @zsolt I want to connect it from another container Commented Nov 14, 2022 at 20:33
  • show us the "docker ps" and "docker network ls" command outputs and share any other info you have Commented Nov 14, 2022 at 20:49
  • @zsolt additional information added ("docker ps" and "docker network ls" and "iptables -L") Commented Nov 15, 2022 at 8:02
  • 1
    that helped to identify your problem, see my edited answer below Commented Nov 15, 2022 at 9:59

1 Answer 1

1

Working fine for me with Compose V2 that is the docker compose subcommand. Your problem is that you are still using the old docker-compose cli. Try docker compose up without a dash between docker and compose.

If you don't have Compose V2 yet, upgrade to it, this site walks you through it: https://www.howtogeek.com/devops/how-to-upgrade-to-docker-compose-v2/

or you can check the docker docs: https://docs.docker.com/compose/install/

$ docker ps

CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS         PORTS      NAMES
f86a00472ece   postgres:12   "docker-entrypoint.s…"   4 minutes ago   Up 3 minutes   5432/tcp   test-heritagebuxfr-postgres-1

$ docker network ls

NETWORK ID     NAME                                                        DRIVER    SCOPE
4f6e933d9297   test_heritagebuxfr                                          bridge    local

$ docker run -it --rm --network test_heritagebuxfr postgres psql -h heritagebuxfr-postgres -U heritagebuxfr

Password for user heritagebuxfr:
psql (15.1 (Debian 15.1-1.pgdg110+1), server 12.13 (Debian 12.13-1.pgdg110+1))
Type "help" for help.

heritagebuxfr=# \l
                                                          List of databases
     Name      |     Owner     | Encoding |  Collate   |   Ctype    | ICU Locale | Locale Provider |        Access privileges
---------------+---------------+----------+------------+------------+------------+-----------------+---------------------------------
 heritagebuxfr | heritagebuxfr | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            |
 postgres      | heritagebuxfr | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            |
 template0     | heritagebuxfr | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            | =c/heritagebuxfr               +
               |               |          |            |            |            |                 | heritagebuxfr=CTc/heritagebuxfr
 template1     | heritagebuxfr | UTF8     | en_US.utf8 | en_US.utf8 |            | libc            | =c/heritagebuxfr               +
               |               |          |            |            |            |                 | heritagebuxfr=CTc/heritagebuxfr
(4 rows)
Sign up to request clarification or add additional context in comments.

10 Comments

I updated to Compose V2, delete containers, delete network, recreate them with docker compose command but still don't work :(. Note I had to switch to iptable-legacy (github.com/docker/for-linux/issues/927#issuecomment-751752610) and this, before switch to compose V2.
So you are on a Debian 10 based distro (ubuntu)? what is the output of cat /etc/os-release?
It's a Debian 10 (migrated from debian 9). I add the command result to my question.
I added docker network detail too
Yes it is a guess based on the github issue you mentioned and the one it is also referring to: github.com/docker/for-linux/issues/927#issuecomment-751752610 All the commenters on these threads have Debian 10 but maybe because Deb 11 was not yet released when the issue arised for them. If I were you I would test this theory by setting up a vm for both versions and try to reproduce your issue.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.