Hi, I have installed docker on a OracleLinux 9.4 Virtual machine and I have builded an image FROM oraclelinux:8.10 and installed some stuff manually, including openssh, postgresql17, etc.
In the Dockerfile I have:
USER postgres
works fine: RUN /usr/pgsql-17/bin/initdb -D /var/lib/pgsql/17/data
do nothing: RUN /usr/pgsql-17/bin/postgres -D $PGDATA -k /var/run/postgresql -p 5432 > $PGDATA/logfile 2>&1 &
FInally
USER root
EXPOSE 5432
EXPOSE 22
CMD [“/usr/sbin/sshd”, “-D”]
I run the container with docker run -d --publish-all --name pgw01 pgsqldb
[admin@buda pgsqldb]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
70f55332a895 pgsqldb “/usr/sbin/sshd -D” 5 seconds ago Up 5 seconds 0.0.0.0:32772->22/tcp, [::]:32772->22/tcp, 0.0.0.0:32773->5432/tcp, [::]:32773->5432/tcp pgw01
From a windows power shell sesion I can connect (ssh) without problem to the container and start the postgress instance
----POWER SHELL SESSION ----
[root@70f55332a895 ~]# su - postgres
[postgres@70f55332a895 ~]$ echo $PGDATA
/var/lib/pgsql/17/data
[postgres@70f55332a895 ~]$ ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 15:30 ? 00:00:00 /usr/sbin/sshd -D
root 7 1 0 15:32 ? 00:00:00 sshd: root [priv]
root 9 7 0 15:33 ? 00:00:00 sshd: root@pts/0
root 10 9 0 15:33 pts/0 00:00:00 -bash
root 25 10 0 15:33 pts/0 00:00:00 su - postgres
postgres 26 25 0 15:33 pts/0 00:00:00 -bash
postgres 55 26 0 15:33 pts/0 00:00:00 ps -ef
The I run the command doing nothing from Dockerfile
[postgres@70f55332a895 ~]$ /usr/pgsql-17/bin/postgres -D $PGDATA -k /var/run/postgresql -p 5432 > $PGDATA/logfile 2>&1 &
[1] 56
[postgres@70f55332a895 ~]$
[postgres@70f55332a895 ~]$ ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 15:30 ? 00:00:00 /usr/sbin/sshd -D
root 7 1 0 15:32 ? 00:00:00 sshd: root [priv]
root 9 7 0 15:33 ? 00:00:00 sshd: root@pts/0
root 10 9 0 15:33 pts/0 00:00:00 -bash
root 25 10 0 15:33 pts/0 00:00:00 su - postgres
postgres 26 25 0 15:33 pts/0 00:00:00 -bash
postgres 56 26 0 15:35 pts/0 00:00:00 /usr/pgsql-17/bin/postgres -D /var/lib/pgsql/17/data -k /var/run/pos
postgres 57 56 0 15:35 ? 00:00:00 postgres: logger
postgres 58 56 0 15:35 ? 00:00:00 postgres: checkpointer
postgres 59 56 0 15:35 ? 00:00:00 postgres: background writer
postgres 61 56 0 15:35 ? 00:00:00 postgres: walwriter
postgres 62 56 0 15:35 ? 00:00:00 postgres: autovacuum launcher
postgres 63 56 0 15:35 ? 00:00:00 postgres: logical replication launcher
postgres 64 26 0 15:35 pts/0 00:00:00 ps -ef
[postgres@70f55332a895 ~]$ psql
psql (17.2)
Type “help” for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges
-----------±---------±----------±----------------±--------±------±-------±----------±----------------------
postgres | postgres | SQL_ASCII | libc | C | C | | |
template0 | postgres | SQL_ASCII | libc | C | C | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | libc | C | C | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
(3 rows)
postgres=#\q
I have two questions:
1.- Why is not working the postgres start up from Dockerfile?
2.- When I tryed to connect remotly to the postgres intance, the connection is refused
psql -U postgres -h 192.168.0.160 -p 32773
psql: error: connection to server at “192.168.0.160”, port 32773 failed: Connection refused (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections?
192.168.0.160: IP running the container
172.17.0.2 : IP container
32773 : Host’s port binding container postgres port 5432
Thank you very much
kind regards
Mauricio Fernández