Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tHpin-00A8Zd-7z for pgsql-general@arkaria.postgresql.org; Sun, 01 Dec 2024 19:35:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tHpij-009rqN-TA for pgsql-general@arkaria.postgresql.org; Sun, 01 Dec 2024 19:35:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tHpij-009rqE-Cj for pgsql-general@lists.postgresql.org; Sun, 01 Dec 2024 19:35:06 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tHpih-000Wfk-3N for pgsql-general@postgresql.org; Sun, 01 Dec 2024 19:35:04 +0000 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-5d0d71d7f00so1472729a12.3 for ; Sun, 01 Dec 2024 11:35:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733081701; x=1733686501; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=91AF8K7qBkiufwsVNumFMj7lkVUD1A5QeGjwfiL7HS0=; b=c64Kfi1DDhp86oVcdQyom3El00ulZxi9SnrGcdSMg+87UJVLeUsD19cH9dLVL3jZ5B Wc6lnkNB3BXpoPVivMW3qomB6mFQsM+FnwO6f7lJOnjRZfGjYiTKbhZv1zQoIK5o2SK1 uD9FSWlSvVc608ifPlJBtYVNUynQak6rBU8NN65QNkDZg5BDyaESrDCRUtKa6NPX0EVU XtlXnz42+lnSEESPnwBLBfTDyC3Doc9A6L4Ukyg6M1dud8DgNQXceT2s/ft+7z1dufSm goQ+ZhMJBHp8mBVg0mEJd3c96e1uk+5Azf8aznXRZymqZVWteQzf4EF+kRrEQA1h28zn LyHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733081701; x=1733686501; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=91AF8K7qBkiufwsVNumFMj7lkVUD1A5QeGjwfiL7HS0=; b=UyRKYI7llXhO+w+WkmXO6DrCoNSmCAmSwKy1elXeQNfQV31M02cmsYe5ZGf7ajhXnE fY72Lx7o7Iilj9nWTnQU/DBMP4+OfZIObqPTRPrNNdkYrs459fOPATFAAOyLCCzURet5 YU1QdBgxd8WyH8p5w+I0GwczapcMcWxSY18IpkbO/wsL4VGN0e1aOLoSOWsNaQDfdglQ Od7fu2lxecvvpq9tPWUAdijUlbMtMWMM/UbGz0jmJmNLWDA0WViZ9vHhh3w9rF3ikOCO sHtfgP6aVsB1DbXo810JhqcEAcJ1vN++NjMbZIHxSx09pC08kROknRLXV4W9vcRrKrme nQhQ== X-Gm-Message-State: AOJu0YzsqkyC4URZQUObVU6QTptP3ZHBOCsV1ORnmhoyLEYYWUH6I6+7 YWqrpg8UMUM+PtMZJrZ3u2Z5054BaL8DRVv0zl/Xg6VMnanw+8OhRF1P8q9VU3DnZ27OB8T3RjJ mufRismLM4wehCxQ8dL4IGpGAjGVLbVg0 X-Gm-Gg: ASbGnctzOyNgULHlpR78bVZCbXGRy09DE754GTBvpFxTYbgxTp4d2OetPn1geb7/xzc OIV0Or/s3XULgToC6D1mGZzDlceIGOuFrV7lFgQPoKqMKSlA7FV5SXy7cnwua/DcBoA== X-Google-Smtp-Source: AGHT+IGHg5LkpHCHuvXO8Ji9Xq1sUCYuramwsa9XZnw+DzxvUynrRHt6imfbcjfpSsGsQTqnxiP/Xl2XxRAVt2vDtNM= X-Received: by 2002:a05:6402:26cb:b0:5d0:8e7e:b961 with SMTP id 4fb4d7f45d1cf-5d08e7ebafamr22233605a12.0.1733081700523; Sun, 01 Dec 2024 11:35:00 -0800 (PST) MIME-Version: 1.0 From: Alexander Farber Date: Sun, 1 Dec 2024 20:34:48 +0100 Message-ID: Subject: Connection to 127.0.0.1 refused in a Dockerfile based on postgres:17-alpine3.20 To: pgsql-general Content-Type: multipart/alternative; boundary="00000000000020793106283a878b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000020793106283a878b Content-Type: text/plain; charset="UTF-8" Good evening, I am trying to create a Dockerfile for development purposes, which would run Jetty and PostgreSQL. The PostgreSQL related part is below: FROM postgres:17-alpine3.20 RUN apk update && apk upgrade && apk add --no-cache curl wget openjdk21 tini # Tell docker-entrypoint.sh to create superuser "postgres" # with password "mypassword" and database "postgres" ENV POSTGRES_PASSWORD mypassword # Tell docker-entrypoint.sh to change these params in postgresql.conf ENV POSTGRES_INITDB_ARGS "--set port=6432 --set max_connections=20 --set max_wal_size=2GB" # The PostgreSQL port is changed from 5432 to 6432 to emulate pg_bouncer ENV PGPORT 6432 ENV PGUSER words ENV PGPASSWORD mypassword WORKDIR /docker-entrypoint-initdb.d COPY ["run-after-initdb.sh", "."] RUN chmod +x run-after-initdb.sh && cat run-after-initdb.sh USER postgres EXPOSE 6432 9090 ENTRYPOINT ["/sbin/tini", "--"] CMD ["sh", "-c", "docker-entrypoint.sh postgres & cd $JETTY_BASE && sleep 10 && java -Djdbc.drivers=org.postgresql.Driver -jar $JETTY_HOME/start.jar"] And below is my run-after-initdb.sh script: #!/bin/sh createuser --username=postgres words psql --username=postgres -c "GRANT USAGE ON SCHEMA public TO words;" psql --username=postgres -c "ALTER USER words PASSWORD 'mypassword';" for L in de en ru fr nl pl; do createdb --username=postgres --owner=words words_$L cd /dict/$L && psql words_$L < words_$L.sql done Then I build and run the docker image and that works without errors: # docker build -t my_docker_image --progress=plain . # docker run --name my_container -p 8080:8080 -p 6432:6432 my_docker_image When I connect to the docker container via terminal, I am able to connect with "psql words_de" command. But the "psql -h localhost words_de" command fails: psql: error: connection to server at "localhost" (127.0.0.1), port 6432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? connection to server at "localhost" (::1), port 6432 failed: Address not available Is the server running on that host and accepting TCP/IP connections? I need the connection via 127.0.0.1 though, because of my Java servlet hosted by the Jetty. I have looked at the config files and env vars: # ls -al /var/run/postgresql/ srwxrwxrwx 1 postgres postgres 0 Dec 1 19:06 .s.PGSQL.6432 -rw------- 1 postgres postgres 64 Dec 1 19:06 .s.PGSQL.6432.lock # echo $PGDATA /var/lib/postgresql/data # grep -v '^#' $PGDATA/pg_hba.conf local all all trust host all all 127.0.0.1/32 trust host all all ::1/128 trust local replication all trust host replication all 127.0.0.1/32 trust host replication all ::1/128 trust # grep -v '^.*#' $PGDATA/postgresql.conf listen_addresses = '*' max_wal_size = 2GB min_wal_size = 80MB log_timezone = UTC datestyle = 'iso, mdy' timezone = UTC default_text_search_config = 'pg_catalog.english' Is anybody able spotting, what am I doing wrong here? Thank you TLDR "psql words_de" works, but "psql -h localhost words_de" does not Best regards Alex --00000000000020793106283a878b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Good= evening,

I am trying to create a Dockerfile for develop= ment purposes, which=C2=A0
would run Jetty and PostgreSQL. The Po= stgreSQL related part is below:

FROM postgres:17-alpine3= .20
RUN apk update && apk upgrade && apk add --no= -cache curl wget openjdk21 tini

# Tell docker-entr= ypoint.sh to create superuser "postgres"
# with passwor= d "mypassword" and database "postgres"
ENV PO= STGRES_PASSWORD mypassword

# Tell docker-entrypoin= t.sh to change these params in postgresql.conf
ENV POSTGRES_INITD= B_ARGS "--set port=3D6432 --set max_connections=3D20 --set max_wal_siz= e=3D2GB"

# The PostgreSQL port is changed fro= m 5432 to 6432 to emulate pg_bouncer
ENV PGPORT 6432
EN= V PGUSER words
ENV PGPASSWORD mypassword

WORKDIR /docker-entrypoint-initdb.d
COPY ["run-after-initdb= .sh", "."]
RUN chmod +x run-after-initdb.sh &&= amp; cat run-after-initdb.sh

USER postgres

EXPOSE 6432 9090

ENTRYPOINT [&qu= ot;/sbin/tini", "--"]

CMD ["sh= ", "-c", "docker-entrypoint.sh postgres & cd $JETTY= _BASE && sleep 10 && java -Djdbc.drivers=3Dorg.postgresql.D= river -jar $JETTY_HOME/start.jar"]

And below is my run-after-in= itdb.sh script:

#!/bin/sh

createuser -= -username=3Dpostgres words

psql --username=3Dpostg= res -c "GRANT USAGE ON SCHEMA public TO words;"
psql --= username=3Dpostgres -c "ALTER USER words PASSWORD 'mypassword'= ;"

for L in de en ru fr nl pl; do
= =C2=A0 =C2=A0 createdb --username=3Dpostgres --owner=3Dwords words_$L
=
=C2=A0 =C2=A0 cd /dict/$L && psql words_$L < words_$L.sql
done

Then I build and run the docker image and that = works without errors:

# docker build -t my_docker_image --progr= ess=3Dplain .
# docker run --name my_container -p 8080:8080 -p 64= 32:6432 my_docker_image

When I connect to the docker container via t= erminal,=C2=A0
I am able to connect with "psql words_de"= ; command.

But the "psql -h localhost words_de" command fa= ils:

psql: error: connection to server at "localhost"= (127.0.0.1), port 6432 failed: Connection refused
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 Is the server running on that host and accepting TCP/IP conne= ctions?
connection to server at "localhost" (::1), port= 6432 failed: Address not available
=C2=A0 =C2=A0 =C2=A0 =C2=A0 I= s the server running on that host and accepting TCP/IP connections?

= I need the connection via 127.0.0.1 though,=C2=A0
because of my J= ava servlet hosted by the Jetty.

I have looked at the config files a= nd env vars:

# ls -al /var/run/postgre= sql/
srwxrwxrwx=C2=A0 =C2=A0 1 postgres postgres=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A00 Dec=C2=A0 1 19:06 .s.PGSQL.6432
-rw-------=C2= =A0 =C2=A0 1 postgres postgres=C2=A0 =C2=A0 =C2=A0 =C2=A0 64 Dec=C2=A0 1 19= :06 .s.PGSQL.6432.lock

# echo $PGDATA
/var/lib= /postgresql/data

# grep -v '^#' $PGDATA/pg_hba.conf
local=C2=A0 =C2=A0all=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0all= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0trust
= host=C2=A0 =C2=A0 all=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0all=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0127.0.0.1/32=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 trust
host=C2=A0 =C2=A0 all=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0all= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0::1/128=C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0trust
local=C2=A0 =C2= =A0replication=C2=A0 =C2=A0 =C2=A0all=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0trust
host=C2=A0 =C2=A0 replication=C2=A0 =C2= =A0 =C2=A0all=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0127.0.0.1/32=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= trust
host=C2=A0 =C2=A0 replication=C2=A0 =C2=A0 =C2=A0all=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0::1/128=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0trust

# grep -v '^.*#'= $PGDATA/postgresql.conf
listen_addresses =3D '*'
max_wal_size =3D 2GB
min_wal_size =3D 80MB
log_timez= one =3D UTC
datestyle =3D 'iso, mdy'
timezone = =3D UTC
default_text_search_config =3D 'pg_catalog.english= 9;

Is anybody able spotting, what am I doing wrong here? Thank you
TLDR "psql words_de" works, but "psql -h localhost wor= ds_de" does not

Best regards
Alex

<= /div>
--00000000000020793106283a878b--